vbams-wordcontentcontrol

Loop through CheckBoxes changing tag


I'm trying to change the Tag of a bunch of CheckBoxes (Content Control), so the tags match the CheckBox row position on a table.

Ex.: If CheckBoxes are positioned on row 4, i want all of them to have the same tag (like Row4,or something like that).

Is this possible or the Tag property is only for reading purpose?

I'll be gratefull on any advise. Thanks in advance!

Image of the table bellow

enter image description here


Solution

  • A basic example:

    Sub Tester()
        Dim cc As ContentControl, i As Long, tbl As Table, rw As Row
        
        Set tbl = ThisDocument.Tables(1)
        For Each rw In tbl.Rows
            i = i + 1
            For Each cc In rw.Range.ContentControls
                If cc.Type = wdContentControlCheckBox Then
                    Debug.Print cc.Tag
                    cc.Tag = "Row_" & i
                End If
            Next cc
        Next rw
    End Sub