Move up a folder in VBA (EXCEL)

  • Thread starter Thread starter Buffyslay
  • Start date Start date
B

Buffyslay

hi

i am currently using the command

thisworkbook.path

if i want to go up a folder, and i was using html i would go ..\ but
how do i do this in VBA?
 
Try this;


Sub Test()
Set fso = CreateObject("scripting.filesystemobject")
Set x = fso.getfolder(ThisWorkbook.Path)
MsgBox x.parentfolder
End Sub
 
U can do it using fso as FileSystemObject
and from there u can get the ParentFolder.

Hope that helps.
Parag.
 
Depending on what you are doing, you can use "\.."

for example. If I want to check on the existence of the file File2.xls in
the directory above the activeworkbook: (demo'd from the immediate window).

? activeworkbook.Path
C:\Data\Data1\Data2
sStr = ActiveWorkbook.Path & "\..\"
? sStr
C:\Data\Data1\Data2\..\
? dir(sStr & "File2.xls")
file2.xls
 

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

Similar Threads

Excel VBA in Citrix. 0
Creating folders using VBA 2
Trouble Installing Excel VBA Code Cleaner into Office 365 0
Two Question 1
Alarm 2 2
The Basics 4
VBA userform Vlookup Excel 1
Hiding an Excel file using VBA 1

Back
Top