Return to VBA Code Examples

VBA Get File Name with GetFileName (FSO)

This short tutorial will demonstrate how to use the GetFileName method of the FileSystemObject.

Get File Name with VBA FileSystemObject

This lesson uses the FileSystemObject. In order to use it, you will need to set a reference to the VB script run-time library. See here for more information.

For getting the file name from any path, you can use:

FileName variable will then hold the value of “ExampleFile.txt”, FileNameWOExt variable will be without the extension “ExampleFile”.

Get File Name Without Extension

As noted above, to get the file name without extension use this line of code:


VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as

Learn More!