1

我想使用 VBA在导出的 Word 文档 (.docx) 中删除所有受保护的评论。

评论受到它们所依赖的某种字段的保护(但是,无论有没有 VBA,我都找不到删除这种保护的方法)。从应用程序(Polarion ALM)导出时会生成这些“字段”。

我试图在 Word Macros 中删除受保护的评论:

Sub MakroRemoveComment()

If ActiveDocument.ProtectionType <> wdNoProtection Then
 ActiveDocument.Unprotect Password:=strPassword
End If

ActiveDocument.DeleteAllComments

End Sub

但我最终得到以下错误消息:

对象“comment”的方法“DeleteAllComments”失败。

我想这是由于评论字段的保护。

截屏:

在此处输入图像描述

4

1 回答 1

1

刚刚偶然发现了这个问题,因为删除这些元素的保护的代码有什么价值(德语中的“Inhaltssteuerelemente”)

Private Sub UnprotectDocument()
    Set doc = ActiveDocument
' Unprotect the document
    If doc.ProtectionType <> wdNoProtection Then
        doc.Unprotect
        doc.Protect Type:=wdNoProtection
    End If

' Remove lock from Inhaltssteuerelementen --> Wiki Content
' Iterate through all the content controls in the document
' and remove locks
    Dim cc As ContentControl
    If doc.ContentControls.Count <> 0 Then
    For Each cc In doc.ContentControls
        cc.LockContentControl = True
        cc.LockContents = False
    Next
    End If
End Sub
于 2020-04-24T06:05:54.840 回答