Change directory from VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I move up 1 subfolder from the current path.

Say this msgbox(ThisWorkbook.Path

returns c:\sub1\Sub

How do I get this to go up 1 level so that it return
c:\sub

From the command I would use cd.

Joh
 
This is not something I've done in VBA in particular, but in othe
places I've used this:
../
to indicate going up one folder and it can be used multiple time
(assuming it works at all) to go up as many folders as you like.
Piku
 
John

Sub test()
Dim x As String
x = StrReverse(ThisWorkbook.Path)
x = StrReverse(Right(x, Len(x) - Application.Find("\", x, 1)))
MsgBox x
End Sub

--
XL2002
Regards

William

(e-mail address removed)

| How do I move up 1 subfolder from the current path.
|
| Say this msgbox(ThisWorkbook.Path)
|
| returns c:\sub1\Sub2
|
| How do I get this to go up 1 level so that it returns
| c:\sub1
|
| From the command I would use cd..
|
| John
|
|
 
Not sure whether you want to set that as the current path or just get a
string.

Sub Tester1()
ChDrive ActiveWorkbook.Path
ChDir ActiveWorkbook.Path
ChDir ".."
sDir = CurDir
Debug.Print ActiveWorkbook.Path, sDir
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top