I am trying to build a function that would return the folder path given the filepath.
I.e.,
Function folderPath (filePath as string) as string
End function
If filePath is:
"C:\Users\Owner\Downloads\SMR_HW_Delivery on Site.xlsm"
I want the function to return:
"C:\Users\Owner\Downloads\
This is what I have so far, haven't tested it yet to see if it would work or not. Any suggestions, or revisions, would be greatly appreciated:
Function filePath(pathString, turnType As String) As String
'
' Returns the filename, or the folder path, from a
' folderpath\filename string
'====================================================================
Dim temp As Variant
Dim fileNameonly As String
Dim folderPathonly As String
Dim Length As Integer
'--------------------------------------------------------------------
Length = Len(pathString)
temp = Split(pathString, Application.PathSeparator)
fileNameonly = temp(uBound(temp))
folderPathonly = Mid(pathString, 1, Length - Len(fileNameonly))
If turnType = "File" Then
filePath = fileNameonly
ElseIf turnType = "Folder" Then
filePath = folderPathonly
End If
End Function