Display file path to the current workbook
In order to create a simple subroutine that shows a path to the active workbook follows these steps.
- Open VBA Editor (Alt + F11),
- Insert the following code into your project.
Dim full_path As String
Dim directory_path As String
Dim file_name As String
full_path = ActiveWorkbook.FullName
directory_path = ActiveWorkbook.Path
file_name = ActiveWorkbook.Name
It will display three dialog boxes:
- the full file path,
- file_name + extension
You can also create functions to show you data inside a cell. First, create a module for your worksheet. This easy function will show you a path to the current file inside a cell.
ShowCurrentPath = ActiveWorkbook.FullName
As you can see, the function name is inserted into the cell.