Function RemoveFileExtension(path As String) As String Dim table As Variant Dim fileName As String fileName = path If InStr(fileName, "\") > 0 Then table = Split(Trim(fileName), "\") fileName = table(UBound(table)) End If If InStr(fileName, ".") > 0 Then table = Split(fileName, ".") RemoveFileExtension = Left(path, Len(path) - Len(table(UBound(table))) - 1) Else RemoveFileExtension = path End If End Function
This one is more general:
ReplyDeleteFunction RemoveFileExtension(path As String) As String
Dim table As Variant
Dim fileName As String
fileName = path
If InStr(fileName, "\") > 0 Then
table = Split(Trim(fileName), "\")
fileName = table(UBound(table))
End If
If InStr(fileName, ".") > 0 Then
table = Split(fileName, ".")
RemoveFileExtension = Left(path, Len(path) - Len(table(UBound(table))) - 1)
Else
RemoveFileExtension = path
End If
End Function