vba - 如何使用 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 路径。它没有说如何选择返回哪一个。
解决方案
根据文档的来源,Document.Path属性返回文档的磁盘或 Web 路径。
如果要获取本地文件路径,请使用Document.SaveAs2方法。基本上,您需要将文件保存在硬盘上的任何位置。
推荐阅读
- oracle - 在 oracle 中应用系统日期
- kubernetes - Calico 节点无法使用服务器的 IP 地址构建
- java - 在 Intellij IDEA 中运行 maven 目标全新安装得到错误 Invalid initial heap size: -Xms=256m
- protractor - 如何在量角器中上下滚动
- angular - 在启用 Ivy 的情况下构建 monorepo Angular9 库是不是一个坏主意
- php - 将绝对部分路由到codeigniter中的控制器
- javascript - div 扩展动画最大高度不起作用。高度始终为 0
- amazon-web-services - cassandra 如何对多区域设置中的区域故障做出反应
- c# - “索引超出范围”异常在 DataGridView SelectionChanged 事件中引发而 FormLoad
- ruby-on-rails - #<# 的未定义方法“路径名”
我更新了项目的 Ruby 和 Rails 版本。
红宝石
2.2.3
->2.5.1
导轨
4.1.8
->5.1.7
现在,当我启动服务器时,出现此错误:
F, [2020-02-03T11:15:49.912