Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-09-2024, 02:51 PM
mj_sklarWRK mj_sklarWRK is offline Change Text Colour if CheckBox is marked Windows 11 Change Text Colour if CheckBox is marked Office 2021
Novice
Change Text Colour if CheckBox is marked
 
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
 

Tags
checkboxes, content control



Similar Threads
Thread Thread Starter Forum Replies Last Post
CHange colour of text box if has a tick or a X chris.james Word VBA 1 10-01-2023 12:50 AM
Change Text Colour if CheckBox is marked Change "fill" text colour to no colour darkmaster006 Word VBA 15 08-22-2023 10:10 AM
Change Text Colour/Box Shade if CheckBox is marked cavals07 Word VBA 7 01-30-2023 11:05 AM
Change text colour for content control labels? Toe Word 1 01-17-2019 08:45 AM
How to change line height for marked text (in Word 2007)? ... as default for font? pstein Word 1 01-14-2012 10:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft