Search code examples
vbams-wordword-contentcontrol

Word- VBA- how to clear/reset all content controls in a specific table?


The following code works to clear all rich text and reset all drop down CCs in the entire document

How can I apply this only to the CCs nested in table(4)?

    Dim oCC As ContentControl
    Dim oCCs As ContentControls
    
    Set oCCs = ActiveDocument.ContentControls
    
    For Each oCC In oCCs
        With oCC
            If oCC.Type = wdContentControlText Then
                .Range.Text = ""
            
            ElseIf oCC.Type = wdContentControlDropdownList Then
                .Type = wdContentControlText
                .Range.Text = ""
                .Type = wdContentControlDropdownList
            End If
        End With
    Next

Solution

  • Change:

    Set oCCs = ActiveDocument.ContentControls

    To:

    Set oCCs = ActiveDocument.Tables(4).Range.ContentControls