Lowpar
Lowpar

Reputation: 907

Loop through table in Word and check if checkboxes are ticked

I have 4 columns, each with 2 sets of checkboxes, I was looking to loop through each set and check if both checkboxes were checked, if they are then exit the sub and put the name of the item with 2 checkboxes checked within 1 set in a msgbox.

Set oRow = oTable.Rows
Set oTable = doc.Tables(3)
For Each oRow In oTable.Rows
    With oRow
        If .Cells(3).Range.Text <> .Cells(3).Range.Text <> "Prep" Or .Cells(3).Range.Text <> "Y" Or .Cells(3).Range.Text <> "" Then
            If .Cells(3).ParentContentControl.Checked = True And .Cells(4).ParentContentControl.Checked = True Then 'error here
                MsgBox "The following item has both preparer and reviewer checked:" & .Cells(2)
                Exit Sub
            ElseIf .Cells(5).ParentContentControl.Checked = True And .Cell(6).ParentContentControl.Checked = True Then
                MsgBox .Cell(2)
                Exit Sub
            End If
        End If
    End With
Next oRow

The problem is I keep on getting an error.

Run-time error '438', object does not support this property or method.

Upvotes: 0

Views: 1287

Answers (1)

Kazimierz Jawor
Kazimierz Jawor

Reputation: 19067

To get access to ContentControl embedded in table, in cell, you need the following reference:

If .Cells(3).Range.ContentControls(1).Checked = True And .Cells(4).Range.ContentControls(1).Checked = True Then

Upvotes: 1

Related Questions