【问题标题】:VBA for Word - UNC PathsVBA for Word - UNC 路径
【发布时间】:2020-08-24 11:51:52
【问题描述】:

我有一个 Word 文档,它使用 VBA 表单根据选择框生成文档内容。 VBA 从其他 Word 文档复制并粘贴到主文档中。我使用显式路径来指定它应该去哪里找到单词文档。

改用 UNC 路径会很好,以删除文件位置 (c:\Files\Example\Content\PROFILE.docx) 的一些“明确性”,并可能将其替换为“..\内容\配置文件.docx " 代码示例:

Sub GenerateProfile()

  Dim currentPathProfile As String

  currentPathProfileText = ActiveDocument.Path

  currentPathProfileText = currentPathProfileText & "c:\Files\Example\Content\PROFILE.docx"

  Documents.Open FileName:=currentPathProfileText
  
  Dim currentPathProfileDoc As Document

  Set currentPathProfileDoc = Documents(1)

  currentPathProfileDoc.Activate
  
  Call CopyWholeContent

  currentPathProfileDoc.Close

  Call PasteWholeContent

End Sub

【问题讨论】:

  • 您在询问 UNC 路径,但您似乎在询问 相对路径

标签: vba ms-word unc


【解决方案1】:

如果其他 word 文档与包含代码的模板处于相对路径位置,则可以这样做。如果它们位于子文件夹中,则更容易。生成 ThisDocument (您的代码持有者)的路径并将其用作基础。 ThisDocument.Path

但是,与其从文档中提取,为什么不将文本以自动图文集的形式存储在模板中并使用它呢?如果在多个模板中需要该信息,则可以将其作为自动图文集存储在全局模板中。这更灵活,更不容易出现问题,IMO。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-22
    • 1970-01-01
    • 2010-09-10
    • 1970-01-01
    • 2010-10-15
    • 1970-01-01
    相关资源
    最近更新 更多