Option Explicit
Public Enum PathReturn
GetPath = 1
GetFile = 0
End Enum
Public Function StripFileOrPath(FullPath As String, _
ReturnType As PathReturn) As String
Dim szPathSep As String
szPathSep = Application.PathSeparator
Dim szCut As String
szCut = CStr(Empty)
Dim i As Long
i = Len(FullPath)
Dim szPath As String
Dim szFile As String
If i > 0 Then
Do While szCut <> szPathSep
szCut = Mid$(FullPath, i, 1)
If szCut = szPathSep Then
szPath = Left$(FullPath, i)
szFile = Right$(FullPath, Len(FullPath) - i)
End If
i = i - 1
Loop
Select Case ReturnType
Case GetPath
StripFileOrPath = szPath
Case GetFile
StripFileOrPath = szFile
End Select
Else
StripFileOrPath = CStr(Empty)
End If
End Function
Sub TestItForExcel()
MsgBox StripFileOrPath(ThisWorkbook.FullName, GetFile)
MsgBox StripFileOrPath(ThisWorkbook.FullName, GetPath)
End Sub
|