简体   繁体   中英

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" )

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

Just pack the ThecurrentDirectory in another fso.GetParentFolderName.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM