Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Get just the file name from a full path (See related posts)

Can be used from VBA or as user defined function on worksheet . Shows that recursion can be used in user defined function .

   1  
   2   Function GetFilenameFromPath(ByVal strPath As String) As String
   3  ' Returns the rightmost characters of a string upto but not including the rightmost '\'
   4  ' e.g. 'c:\winnt\win.ini' returns 'win.ini'
   5      
   6      If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then
   7          GetFilenameFromPath = GetFilenameFromPath(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)
   8      End If
   9  End Function


You need to create an account or log in to post comments to this site.


Click here to browse all 5502 code snippets

Related Posts