我在Excel中使用VBA创建了一些简单的文件,这些文件应该保存在与Excel文件相同的位置。
我用这个来获取excel文件的位置:
ActiveWorkbook.Path
问题是,这总是返回OneDrive URL,如下所示:
https://d.docs.live.net/641ebe6d8******/Work/Projects.......
我要找的是我硬盘上的物理位置。
我试过关闭我的计算机上的OneDrive应用程序,并从目录本身打开文件,但仍然从上面的位置给了我一个OneDrive URL.
任何想法如何得到我的硬盘驱动器上的目录路径代替?
3条答案
按热度按时间gcxthw6b1#
您可以使用下面的helper函数获取文件的物理路径,即使它保存在OneDrive/Microsoft Teams文件夹中。
它基本上会循环通过Windows注册表项存储同步文件夹路径,并返回一个匹配您的文件URL。
thtygnil2#
解决方案是OneDrive设置。
取消选中“使用Office应用程序sunc我打开的Office文件”将使其使用本地目录。即使在我的计算机上关闭OneDrive应用程序时,这种效果也是真实的。
1l5u6lss3#
好吧,我知道这篇文章很老了,但我只是想让你知道我找到了一个简单的解决方法: