Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the path of current worksheet in VBA?

Tags:

excel

vba

People also ask

How do I find the file path in excel VBA?

Use Application. ActiveWorkbook. Path for just the path itself (without the workbook name) or Application.

How do I find the path of an excel spreadsheet?

Press F12. Excel displays the Save As dialog box. Click once in the Location Bar at the top of the dialog box. Excel displays the path in which the current workbook is located.


Use Application.ActiveWorkbook.Path for just the path itself (without the workbook name) or Application.ActiveWorkbook.FullName for the path with the workbook name.


Always nice to have:

Dim myPath As String     
Dim folderPath As String 

folderPath = Application.ActiveWorkbook.Path    
myPath = Application.ActiveWorkbook.FullName

If you want to get the path of the workbook from where the macro is being executed - use

Application.ThisWorkbook.Path

Application.ActiveWorkbook.Path can sometimes produce unexpected results (e.g. if your macro switches between multiple workbooks).


The quickest way

path = ThisWorkbook.Path & "\"