VBA 03 - 应用程序路径 - 获取父文件夹 [英] VBA 03 - Application Path - get to Parent Folder

查看:391
本文介绍了VBA 03 - 应用程序路径 - 获取父文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用程序:Excel

Application: Excel

Left(ThisWorkbook.Path, InStrRev(ThisWorkbook.Path, "\") - 1)

我需要从工作簿路径返回至少2个文件夹。

I need to go back at least 2 Folders from the Workbook Path.

不能使用像C:/ Folder1这样的路径,因为应用程序将被移动多次。

I cannot use Paths like "C:/Folder1", because the Application will be moved multiple times.

推荐答案

像这样:

Function getParentFolder2(ByVal strFolder0)
  Dim strFolder
  strFolder = Left(strFolder0, InStrRev(strFolder0, "\") - 1)
  getParentFolder2 = Left(strFolder, InStrRev(strFolder, "\") - 1)
End Function


Dim strFolder
strFolder = getParentFolder2(ThisWorkbook.Path)

我们在这里剪两次\subdir模式...

We here cut twice \subdir pattern...

这篇关于VBA 03 - 应用程序路径 - 获取父文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆