我希望在导出的word文档(.docx)中使用删除所有受保护的注释。
注释受到它们所依赖的某种字段的保护(但是,无论是否使用VBA,我都找不到一种方法来删除这种保护)。这些“字段”是在从应用程序导出时生成的(Polarion )。
我试图在“宏”一词中删除受保护的注释:
Sub MakroRemoveComment()
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=strPassword
End If
ActiveDocument.DeleteAllComments
End Sub但我最后得到了以下错误消息:
对象'DeleteAllComments‘的方法“注释”失败。
我想这是由于对评论字段的保护。
截图:

发布于 2020-04-24 06:05:54
只是无意中发现了这个问题,因为删除这些元素的保护的代码有什么价值(德语中的“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 Subhttps://stackoverflow.com/questions/53049688
复制相似问题