Paste the following function in a standard module:
Function Extract_file_name(vFile As String) As String
pos = 0
For i = Len(vFile) To 1 Step -1
If Mid(vFile, i, 1) = "\" Then
pos = i
Exit For
End If
Next
Extract_file_name = Right(vFile, Len(vFile) - pos)
End Function
You can then call the function from anywhere in your project, passing
the directory path string as argument:
Extract_file_name("D:\documents\file1.txt")
and it will return the file name.