I'm using Word 2021 to create a checklist form that contains several dozen questions, each with three checkboxes: yes, no, N/A. The checkboxes are all named using titles along the lines of "ChkYes_1", "ChkYes_2", "ChkNo_2" etc.
I would like the questions and checkboxes to change colour based on the responses (e.g. turn green if "yes" or red if "no").
I've figured out how to do this for one row of checkboxes, calling the checkboxes by title in the code. Is there a way to adapt this code to apply to all the questions, without needing to duplicate this section of code for each unique title?
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Dim VarCLR As Long
Dim i As Long
With CCtrl
Select Case .Title
Case "Chk1BNo_1"
Select Case .Checked
Case True: VarCLR = wdRed
Case Else: VarCLR = wdAuto
End Select
ActiveDocument.SelectContentControlsByTitle("Chk1BNo_1")(1).Range.Font.ColorIndex = VarCLR
ActiveDocument.SelectContentControlsByTitle("Text1B_1")(1).Range.Font.ColorIndex = VarCLR
End Select
End With
End Sub