How to Get the File Path and File Name using Excel VBA?

In this post, you will be learning how to get the full File Path and File name using Excel VBA in your Excel Spreadsheet.

The file path and file name using Excel VBA can be accessed using the ‘.Path’ and ‘.FullName‘ properties.

How to Get the File Path using Excel VBA?

.Path Property

The Path property returns the complete, saved path of the workbook -Excel file.

How to Get File Name using Excel VBA?

.FullName Property

The FullName property returns the complete, saved path, including the name of the workbook.

Let’s see these properties with the help of an example.

  • Create an Excel file and name it of your choice.
  • Firstly, place a command button on your worksheet using the insert option in the Developer tab
How to Get File Name using Excel VBA?

 Enter the following code in the VBA of the button:

How to Get the File Path and File Name using Excel VBA?
MsgBox Workbooks("Developerpublish.com-Path and full name.xlsm.xlsm").Path

This returns the complete path to the current excel file.

How to Get the File Path and File Name using Excel VBA?
MsgBox ActiveWorkbook.FullName

This line returns the complete path, including the name of the active workbook.

How to Get the File Path and File Name using Excel VBA?

You need to enter the exact file name to find its path.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Hey, wait!Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.