Public Function GetFileName(ByVal FullPath As String) As String
'**************************************************
'* Created By: Scott L. Prince
'* Created On: 10/2/13
'* Modified:
'* Purpose: Returns a file name from the full path provided.
'* Parameters: Full path including file name
'* Output: File name, or empty string if no file name could be determined.
'* Comments:
'**************************************************
On Error GoTo GetFileName_Err
'Only necessary if a FullPath has actually been passed.
If FullPath <> "" Then
Dim BackslashLocation As Long 'Location of the last "/" or "\" in the path
'Locate the FINAL backslash.
BackslashLocation = InStrRev(FullPath, "\")
'If no "\" was found, then check for "/" (sharepoint file structure).
If BackslashLocation = 0 Then BackslashLocation = InStrRev(FullPath, "/")
'Determine if a slash was found.
If BackslashLocation > 0 Then
'A slash was found, so return the file name.
GetFileName = Right(FullPath, Len(FullPath) - BackslashLocation)
Else
'No slash found, so return FullPath as the file name.
GetFileName = FullPath
End If
End If
GetFileName_Exit:
Exit Function
GetFileName_Err:
MsgBox "An error has occurred in procedure 'GetFileName'!" & vbCrLf & vbCrLf & _
"Error:" & vbTab & vbTab & Err.Number & vbCrLf & _
"Description:" & vbTab & Err.Description, vbOKOnly + vbCritical
Resume GetFileName_Exit
End Function