File Extension Function - VBA

Public Function LastIndexOf(searchIn As String, searchFor As String) As String

    LastIndexOf = InStrRev(searchIn, searchFor)

End Function

Public Function Suffix(searchIn As String, searchFor As String) As String

    Suffix = Right$(searchIn, Len(searchIn) - LastIndexOf(searchIn, searchFor))

End Function

Public Function FileExtension(fileSpec As String)

    Dim afterPeriod As String
    Dim afterSlash As String
    
    afterPeriod = Suffix(fileSpec, ".")
    afterSlash = Suffix(fileSpec, "\")
    
    If Len(afterPeriod) > Len(afterSlash) Then
        FileExtension = ""
    Else
        FileExtension = afterPeriod
    End If

End Function