简体   繁体   English

VBA打开之前的文件夹

[英]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: 如果objFile是文件对象,则可以多次将其ParentFolder属性链接在一起以获得分散的结果:

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 objFile.ParentFolder.ParentFolder = C:\\ Users \\百思买\\下载

Just pack the ThecurrentDirectory in another fso.GetParentFolderName. 只需将ThecurrentDirectory打包到另一个fso.GetParentFolderName中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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