JeanLo
JeanLo

Reputation: 101

VBA open the folder before

I want to open the folder before the current Directory each time. I tried "..\" but it didn't work, can you help me with that N

ThecurrentDirectory= fso.GetParentFolderName(objFile)
Set myWorkBook = myxlApplication.Workbooks.Open( ThecurrentDirectory & "\..\CLIENTS.xlsx" )

Upvotes: 0

Views: 55

Answers (2)

user6432984
user6432984

Reputation:

If objFile is a file object then you can chain it's ParentFolder property together multiple times to get the disred result:

Dim fso, f
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
Set objFile = fso.GetFile("C:\Users\best buy\Downloads\stackoverfow\test.xlsm")

Output:

  • objFile.ParentFolder.ParentFolder = C:\Users\best buy\Downloads

Upvotes: 1

Julian Kuchlbauer
Julian Kuchlbauer

Reputation: 895

Just pack the ThecurrentDirectory in another fso.GetParentFolderName.

ThecurrentDirectory= fso.GetParentFolderName(objFile)
Set myWorkBook = myxlApplication.Workbooks.Open( fso.GetParentFolderName(ThecurrentDirectory) & "\CLIENTS.xlsx" )

Upvotes: 0

Related Questions