Open File Without Calling Filepath

If it is in the same folder, then

Workbooks.Open("ObsReportExcelWorkbook.xlsx")

or

Workbooks.Open(".\ObsReportExcelWorkbook.xlsx")

should work. I just tried both in Excel VBA, with success.


If the file is in the same folder as the document containing your VBA macro, use

ThisWorkbook.Path

for example:

Workbooks.Open(ThisWorkbook.Path & "\ObsReportExcelWorkbook.xlsx")

(this works even if the document is not the active one any more, or you changed the current directory).


If the file name is fixed you can use the ActiveWorkbook.Path function to return the path of the current workbook:

Dim FileName as string FileName = ActiveWorkbook.Path & "\myfile.xlsx

Check if you need that extra slash character.

Tags:

Excel

Vba