0
votes

I read the answers to the question on How to find and disable a content control by tag on SO (below is the code for your convenience). In my case, I need to delete Content Controls (CC) with SPECIFIC tags.

For Example, out of the 150 CCs that I have in the document, I need to find and delete only those CCs with the Tag "DCC"(just the CC, not its contents). As you can tell, I have no/limited experience in VB and would greatly appreciate a script that I can copy/paste.

I'm using Rich Text CCs in Word 2007.

Private Sub DeleteCCByTag_Alternative(ccTag As String)

    Dim cc As ContentControl
    Set cc = ThisDocument.SelectContentControlsByTag(ccTag).Item(1)

    With cc

        .LockContentControl = False
        .LockContents = False

        .Range.Delete               'to delete CC content

        .Delete (False)
    End With
End Sub
1

1 Answers

1
votes

Well, I was able to figure out ONE way of doing this....not the prettiest code and I'm sure there's a better way to do this. But, with my extremely limited VB knowledge, the below is working for my needs:

Sub DeleteCCByTag()
Dim oThisdoc As Word.Document
Dim oCC As ContentControl
Dim oCCs As ContentControls

Set oThisdoc = ActiveDocument
Set oCCs = oThisdoc.SelectContentControlsByTag("DCC")

    For Each oCC In oCCs
    If oCCs.Count > 0 Then
    oCC.Delete False
End If
Next
End Sub