Function file_name_only(file_path As String) As String
Dim temp As Variant
temp = Split(file_path, Application.PathSeparator)
file_name_only = temp(UBound(temp))
End Function
- here you give your file name as input of the function
- the split function of VBA splits the path in different portion by using "\" as path separator & stores them in an array named "temp"
- the UBound() finds the max item number of array and finally assigns the result to "file_name_only" function
Hope this will be helpful.