单击“编辑文档”时的 Word 365 VBA 事件

问题描述 投票:0回答:1

在 Word 2016 中,尽管文档是只读的,但仍可以通过 VBA 进行修改。我们曾经更新标题中的状态标签(脱机、草稿、..、已完成、已替换)(使用文档打开事件),但这在 365 桌面中是不可能的 - 直到单击“编辑文档”(或 LockServerFile) -由获得许可的用户使用。

单击“编辑文档”时似乎不存在运行代码的事件。 有什么想法吗?

此应用程序和文档事件不存在。

如果在只读状态下手动编辑,则会出现“仍然编辑”,-这可能是更好的方法..如果可能的话,从 VBA 进行。

vba events ms-word office365-apps
1个回答
0
投票

您可以在只读文档中自由添加、删除或修改自定义文档属性。也许最简单的方法是拥有自定义文档属性并在标题中包含一个字段。

ActiveDocument.CustomDocumentProperties(PropertyName).Value = "Draft"

之后,只需更新用户标头中的字段即可,这也适用于只读模式。

Public Sub UpdateHeader()
Dim MySec As Word.Section
Dim FirstUpdate As Boolean ' Flag for the loop if any header has been updated yet - makes sure at least the first one gets updated and only linked ones after that are skipped

For Each MySec In ActiveDocument.Sections
    If Not FirstUpdate Or Not MySec.Headers(wdHeaderFooterPrimary).LinkToPrevious Then ' Execute the update on the first header and any header that is not linked to previous
        MySec.Headers(wdHeaderFooterPrimary).Range.Fields.Update
    End If
    FirstUpdate = True
Next MySec
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.