I have the code below and I want it to open a file from my documents folder. The only problem is that every computers path is different to this folder. Does anyone know an easy way to work around and open a file in My Documents without the full path?
I want to eliminate the part of the path in red and make it universal because computers will have a different number.
Operating System: Windows 7
Code below:
I want to eliminate the part of the path in red and make it universal because computers will have a different number.
Operating System: Windows 7
Code below:
Code:
Public Function AddITARPicOffloadAnalysis()
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
With xlApp
Dim wb As Object
Dim ws As Object
Dim Lastrow As Long
On Error Resume Next
[COLOR=seagreen]Set wb = .Workbooks.Open[/COLOR][COLOR=seagreen]("[COLOR=red]C:\Users\f0000\[/COLOR]Documents\Sample.xlsx")
[/COLOR]Set ws = wb.Sheets(1)
'Code below counts the cells with data and selects the last empty cell
Lastrow = ws.UsedRange.Rows.Count
Blankcell = Lastrow + 1
ws.Cells(Blankcell, "I").Select
ws.pictures.insert ("D:\sample.png")
xlApp.Visible = True
LinkToFile = False
SaveWithDocument = True
'ws.SaveAs FileName:="D:\" & BookName
wb.Close , SaveChanges:=True
Set xlApp = Nothing
End With
End Function