首页 > 解决方案 > 如何使用 VBA 获取 word 文档的磁盘路径?Document.Path 改为返回 Web 路径

问题描述

我有一个带有一些 vba 代码的 word 文档。我想返回保存word文档的目录的路径。

这是我使用的代码:

Dim PathCurrentDocument As Variant
PathCurrentDocument = ActiveDocument.path
Debug.Print PathCurrentDocument

所需的输出是:

“C:\Users\firstname.lastname\OneDrive - 公司名称\VBA\4_update_documents_with_vba_inside_word\document_templates_to_modify”

我得到的是网络链接,如下所示:

https://my-company.sharepoint.com/personal/my_name/Documents/VBA/4_update_documents_with_vba_inside_word/Document_A_Template_with_macro.docm

微软文档只说该属性返回文档的磁盘或 Web 路径。它没有说如何选择返回哪一个。

标签: vbams-word

解决方案


根据文档的来源,Document.Path属性返回文档的磁盘或 Web 路径。

如果要获取本地文件路径,请使用Document.SaveAs2方法。基本上,您需要将文件保存在硬盘上的任何位置。


推荐阅读