首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MS Word 2016:使用VBA删除所有受保护的注释

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

Stack Overflow用户
提问于 2018-10-29 16:16:04
回答 1查看 346关注 0票数 1

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

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

我试图在“宏”一词中删除受保护的注释:

代码语言:javascript
复制
Sub MakroRemoveComment()

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

ActiveDocument.DeleteAllComments

End Sub

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

对象'DeleteAllComments‘的方法“注释”失败。

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

截图:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-24 06:05:54

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

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53049688

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档