Get File Name with Excel VBA

Sometimes it is useful to get the file name using Excel VBA. Two methods will either give the file name, or the full file path and file name. When I use either of these methods I tend to assign them to a variable as a string.

Get File Name using VBA

Using VBA I would assign the file name to the variable thus so. Assuming you want to capture the filename of the workbook currently open I would add two lines of code. One to declare the variable, and one to assign the file name to the variable.

Dim FileName as String

FileName = ThisWorkbook.Name

Get File Path & File Name using VBA
To get the file path and file name of the active workbook I would use the same method as above, but change the second line ever so slightly.

Dim FullFileName as String

FullFileName = ThisWorkbook.FullName

So using the examples above will generate the following variables. These are examples only, and file paths will differ:

I see you don’t monetize your site, don’t waste your traffic,
you can earn additional bucks every month because you’ve got hi quality content.
If you want to know how to make extra bucks, search for: Ercannou’s essential adsense alternative

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.