繁体   English   中英

MS Word 2016:使用 VBA 删除所有受保护的注释

[英]MS Word 2016: Remove all protected comments using VBA

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

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

我正在尝试在 Word 宏中删除受保护的注释:

Sub MakroRemoveComment()

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

ActiveDocument.DeleteAllComments

End Sub

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

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

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

截屏:

在此处输入图片说明

刚刚偶然发现了这个问题,因为删除这些元素的保护的代码值得吗(德语中的“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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM