Parse/Extract File Name from Full File Name and Path

< Back to Search results

 Category: [Excel]  Demo Available 

Parse/Extract File Name from Full File Name and Path


Got any Excel/VBA Questions? Free Excel Help

This UDF will extract the file name from a full path name.

The Code

Function FunctionGetFileName(FullPath As String)

Dim StrFind As String

	Do Until Left(StrFind, 1) = "\"

		iCount = iCount + 1

		StrFind = Right(FullPath, iCount)

			If iCount = Len(FullPath) Then Exit Do



	FunctionGetFileName = Right(StrFind, Len(StrFind) - 1)


End Function

To use this UDF push Alt+F11 and go Insert>Module and paste in the code. Push Alt+Q and save. The Function will appear under "User Defined" in the Paste Function dialog box (Shift+F3). 

Enter the function like this.


Where A1 contains you file and path name.


See also:

Excel VBA Find Method
Force Text to Upper Case/Proper Case
Used to Loop Through a Collection or Array
For Loop
For Loop Step
Convert Excel Formulas from Relative to Absolute
Custom Excel Formulas - User Defined Functions/Formulas


See also Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions.


Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


stars (0 Reviews)