1

I would like to remove in an exported word document (.docx) all protected comments using VBA.

The comments are protected by some kind of fields they rely on (however I couldn't find a way to remove this protection with or without VBA). Those "fields" were generated when exporting from the application (Polarion ALM).

I was trying in the Word Macros the following to remove the protected comments:

Sub MakroRemoveComment()

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

ActiveDocument.DeleteAllComments

End Sub

but I ended up with following error message:

The method 'DeleteAllComments' for the object 'comment' failed.

I guess this is due to the protection of the comment fields.

Screenshot:

enter image description here

SteffPoint
  • 479
  • 2
  • 9
  • 24
  • 1
    Do either of these help? https://stackoverflow.com/q/31783956/2727437 – Marcucciboy2 Oct 29 '18 at 16:44
  • Also, I've not been able to find anything about this - how do you protect certain comments in word? – Marcucciboy2 Oct 29 '18 at 16:45
  • 1
    Before we can help we need to know exactly *what kind* of protection this is. You say this is an "exported" document: exported from *where*? What happens when you try to delete a single comment as an end-user? – Cindy Meister Oct 29 '18 at 17:08
  • The document is exported from a web application called Polarion. Within the word document there are work items. Those are some kind of modules (the document in the role of a "container" of those work items). It seems to export those work items as some kind of fields in the word document and the comments are connected to those fields. Now the problem is, that I don't have any kind of option to remove those comments with standard tools from word. – SteffPoint Oct 29 '18 at 19:42
  • Thanks for the link @Marcucciboy2 - Unfortunately it doesn't help out in my use-case – SteffPoint Oct 29 '18 at 19:42
  • Are you able to show us a picture or two of how it looks? I'm having trouble picturing it (note that SO has a built-in photo upload tool in the editor!) – Marcucciboy2 Oct 29 '18 at 20:01
  • @Marcucciboy2: Thanks for your further assistance. I've added a screenshot to the question. – SteffPoint Oct 30 '18 at 06:37

1 Answers1

1

Just stumbled up on the question, for what it is worth the code to remove the protection of those elements ("Inhaltssteuerelemente" in german)

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
Mosesx
  • 26
  • 2