VB Code:
Function GetFileName(FileName As String) As String Dim i As Integer On Error Resume Next For i = Len(FileName) To 1 Step -1 If Mid(FileName, i, 1) = "\" Then Exit For End If Next GetFileName = Mid(FileName, i + 1) End Function
Printable View
VB Code:
Function GetFileName(FileName As String) As String Dim i As Integer On Error Resume Next For i = Len(FileName) To 1 Step -1 If Mid(FileName, i, 1) = "\" Then Exit For End If Next GetFileName = Mid(FileName, i + 1) End Function
Here's my way :)
VB Code:
Function GetFileName (FileName As String) As String FileName = StrReverse(FileName) Dim Pieces() As String Pieces() = Split(FileName, "\", 2) GetFileName = StrReverse(Pieces(0)) End Function
There are some errors in you code ffejy - On the array. Very unique method once it worked.
I like to use something like this.
MsgBox Mid(FileName, InStrRev(FileName, "\") + 1)
Oops, thanks for pointing that out Hawk, fixed now. Your method is the shortest :)