假设您构建了一个宏,该宏使用一些INI和数据文件进行输入或输出,位于同一目录中。您已将路径硬编码到DVB文件中,以便宏知道在何处查找这些文件
最终用户决定在网络服务器驱动器上使用宏。但是客户端PC对此驱动器使用不同的驱动器号。此外,IT部门还会更改应用程序的目录名。结果:宏找不到INI和数据文件
这里有一个解决方案:
- Public Sub GetMyLocation()
- Dim strDVBname As String, strDVBpath As String
- strDVBname = VBE.ActiveVBProject.Name & "."
- strDVBpath = VBE.ActiveVBProject.BuildFileName
- strDVBpath = left(strDVBpath, InStr(strDVBpath, strDVBname) - 1)
- Debug.Print strDVBpath
- ' e.g. strDVBpath will be "AnyDrive:\AnyDir\AnySubdir"
- ' so your macro can access data files in this directory
- ' no matter where the directory is created.
- End Sub
我希望这对一些人有用。
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |