I am working with a macro to copy data between worksheets in multiple folders. For this example the file is
\network_drive\Locations\site\network_scans\year\Month\results.xlsx
I am trying to copy a table from this file to another workbook two directories up. In this case
\network_drive\Locations\site\network_scans\Template.xlsx
I do this with an absolute path:
Sheets("Chart Data").Select
Selection.Copy
Workbooks.Open Filename:= _
"\\network_drive\Locations\site\network_scans\Template.xlsx"
Range("A20").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Save
ActiveWindow.Close
I need this for multiple locations and sites (i.e. site 1, site 2, site 3, etc.). I am trying to make the path relative. If I were doing this manually I would use cd ../../ and then open Template.xlsx.
How do I reference relative paths in VBA?
EDIT
I think I got the syntax but now it generating
Run-time error '1004'
Sorry, we couldn't find C:\Users\USER\AppData\Roaming\Excel\XLSTART Scan Reports \filename.xlsx. Is it possible it was moved, renamed, or deleted?
Sheets("Chart Data").Select
Selection.Copy
Workbooks.Open CStr(ThisWorkbook.Path) & "\..\..\..\network_scans\Template.xlsx"
Range("A20").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Save
End Sub
SNIP
It is addressing the file as if it were on the C drive instead of the network drive. Any thoughts on how to get it to see this as the network path instead of the local path?