Get file name from a path name : Path « File Path « VBA / Excel / Access / Word






Get file name from a path name

 

Public Sub GetFileNameTest()
  MsgBox GetFileName("C:\text.txt")
End Sub

Function GetFileName(ByVal Path As String) As String
  Dim I As Integer
  
  For I = Len(Path) To 1 Step -1
    If Mid(Path, I, 1) = Application.PathSeparator Or Mid(Path, I, 1) = ":" Then Exit For
  Next I
   
  GetFileName = Right(Path, Len(Path) - I)
End Function

 








Related examples in the same category

1.Get the Path Separator
2.Determining whether a path exists