Help With a function!
Posted by RoB on November 12, 2001 2:31 PM
I have this function that Dank wrote for me, and it works great, but I'm having some trouble understanding it exactly. Could someone explain to me more clearly how it works? Currently, it extracts the file name from a given directory ie: in the directory "C:\Temp\10-01\Test.xls", it would return "Test". I'm trying to modify it to get one of the directory names, ie: in the above directory, the function will return "10-01", but I'm not sure how to modify it because Im not sure how it works. Ive tried playing with it, with no success. I appreciate any help, thanks. Heres the function:
Function FilenameOnly(strPath As String) As String
Dim lngCharCounter As Long
'First establish the filename and extenstion part
For lngCharCounter = Len(strPath) To 1 Step -1
If Mid(strPath, lngCharCounter, 1) = "\" Then
FilenameOnly = Right(strPath, Len(strPath) - lngCharCounter)
'Remove the extension
FilenameOnly = Left(FilenameOnly, InStr(1, FilenameOnly, ".") - 1)
Exit For
End If
Next lngCharCounter
End Function