View Single Post
 
Old 02-09-2024, 02:51 PM
mj_sklarWRK mj_sklarWRK is offline Windows 11 Office 2021
Novice
 
Join Date: Feb 2024
Posts: 2
mj_sklarWRK is on a distinguished road
Default Change Text Colour if CheckBox is marked

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
Attached Files
File Type: docm checkboxes autoformat draft.docm (27.6 KB, 7 views)
Reply With Quote