Gets the file name from the path. : File « File Path « VBA / Excel / Access / Word






Gets the file name from the path.

 
Sub GetFileName()
   Dim stPathSep As String
   Dim fileLength As Integer
   Dim i As Integer
   Dim stFullName As String
  
   stFullName = "C:\asdf.xls"
  
   stPathSep = Application.PathSeparator
   fileLength = Len(stFullName)

   For i = fileLength To 1 Step -1
      If Mid(stFullName, i, 1) = stPathSep Then Exit For
         Debug.Print Right(stFullName, fileLength - i + 1)
   Next i
End Sub

 








Related examples in the same category

1.Does the specified file exist?
2.Check file existance
3.List all files under application path
4.Select a folder
5.Select a location containing the files you want to list
6.processes multiple stored files
7.Common File Operations Simplified
8.Use array to store a list of files