Option Explicit
Sub Test()
' hiker95, 04/13/2011
' http://www.mrexcel.com/forum/showthread.php?t=543437
Dim string1 As String, string2 As String
Dim Sp, s As Long
string1 = "C:\mydocuments\text\something\anything"
Sp = Split(string1, "\")
For s = LBound(Sp) To UBound(Sp) - 1
string2 = string2 & Sp(s) & "\"
Next s
If Right(string2, 1) = "\" Then string2 = Left(string2, Len(string2) - 1)
MsgBox string2
End Sub
ericlch16,
Try:
Code:Option Explicit Sub Test() ' hiker95, 04/13/2011 ' http://www.mrexcel.com/forum/showthread.php?t=543437 Dim string1 As String, string2 As String Dim Sp, s As Long string1 = "C:\mydocuments\text\something\anything" Sp = Split(string1, "\") For s = LBound(Sp) To UBound(Sp) - 1 string2 = string2 & Sp(s) & "\" Next s If Right(string2, 1) = "\" Then string2 = Left(string2, Len(string2) - 1) MsgBox string2 End Sub
Sub Foo()
Debug.Print CreateObject("Scripting.FileSystemObject").GetParentFolderName("C:\SomeFolder\SomeFolder")
End Sub
Sub foo()
Dim strArr() As String
Let strArr = Split("C:\Temp\Gooney goo goo", "\")
ReDim Preserve strArr(UBound(strArr) - 1)
MsgBox Join$(strArr, "\")
End Sub
Sub bar()
Const StringVar As String = "C:\Temp\Gooney goo goo"
MsgBox Left$(StringVar, Len(StringVar) - _
WorksheetFunction.Find("\", StrReverse(StringVar)))
End Sub