本文介绍了上一级文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个获取子文件夹数据的宏.但是我也想要主文件夹中的东西.
I have a Macro that gets sub folder data. However I also want something from the main folder.
我查看了如何使用vba获取当前工作目录? /a>,但需要更改activeworkbook路径:
I looked at How to get current working directory using vba? but need to change activeworkbook path:
Application.ActiveWorkbook.Path might be "c:\parent\subfolder"
我想要
"c:\parent\"
使用Excel 365 VBA
Using Excel 365 VBA
推荐答案
由于路径可能不是当前工作目录,因此您需要从字符串中提取路径.
As the path may not be the current working directory you need to extract the path from the string.
找到最后一个\
并读取左侧的所有字符:
Find the last \
and read all characters to the left:
ParentPath = Left$(Path, InStrRev(Path, "\"))
如果您正在当前目录中工作,ChDir ".."
将使您跳到上一级,则CurrDir
可以返回新路径.
If you are working around the current directory ChDir ".."
will jump you up one level, the new path can be returned by CurrDir
.
这篇关于上一级文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!