Extract Path From String
It needs to be compatable with at least XL2000.
"Dave Peterson" wrote in message
...
What version of excel are you using?
xl2k+
Option Explicit
Sub testme()
Dim myStr As String
Dim myPath as string
myStr = "C:\my documents\test folder\test doc.doc"
myPath = Left(myStr, InStrRev(myStr, "\") - 1)
MsgBox myPath
End Sub
before xl2k:
Option Explicit
Sub testme()
Dim myStr As String
Dim myPath As String
Dim iCtr As Long
myStr = "C:\my documents\test folder\test doc.doc"
For iCtr = Len(myStr) To 1 Step -1
If Mid(myStr, iCtr, 1) = "\" Then
myPath = Left(myStr, iCtr - 1)
Exit For
End If
Next iCtr
MsgBox myPath
End Sub
Andibevan wrote:
Hi All,
If I have the following string assigned to var_full "C:\my documents\test
folder\test doc.doc"
What is the best way to extract the path from the above string so that
the
output is "C:\my documents\test folder"
The output string needs to NOT finish in a backslash.
The solution also needs to be able to cope with any number of folder
hierarchies.
Any ideas?
Ta
Andi
--
Dave Peterson
|