![]() |
|
#3
|
|||
|
|||
|
Hi Andrew,
I've made the changes to the tags that you suggested and the code you provided works perfectly! Thank you. Edit: After a little bit more trial-and-error, I managed to write a simple FOR loop that greys out a section, so help with the question below is no longer needed! ![]() I would also like the whole table to change colours if the top checkbox is checked (i.e., "check this box if this section does not apply").Here is the code I used to get a "master" checkbox to grey out a table. The attached file contains the same code but with additional inline comments. Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Dim lngColour As Long, i As Long, aCC As ContentControl
If CCtrl.Type = wdContentControlCheckBox Then 'section 1 - MASTER checkbox disables or re-enables a section
Select Case CCtrl.Tag
Case "MASTER"
lngColour = wdGray50
If CCtrl.Checked Then
For Each aCC In CCtrl.Range.Tables(1).Range.ContentControls
aCC.LockContents = False
aCC.Range.Font.ColorIndex = lngColour
aCC.Range.Font.StrikeThrough = True
If aCC.Type = wdContentControlCheckBox Then
If aCC.Tag <> "MASTER" Then
aCC.Checked = False
End If
End If
aCC.LockContents = True
If aCC.Tag = "MASTER" Then
aCC.LockContents = False
aCC.Range.Font.StrikeThrough = False
End If
Next
End If 'end second IF (If.CCtrl.Checked Then)
If CCtrl.Checked = False Then
For Each aCC In CCtrl.Range.Tables(1).Range.ContentControls
aCC.LockContents = False
aCC.Range.Font.ColorIndex = wdAuto
aCC.Range.Font.StrikeThrough = False
If aCC.Type = wdContentControlRichText Then
aCC.LockContents = True
End If
Next
End If
End Select
End If
If CCtrl.Type = wdContentControlCheckBox Then 'section 2 - colour-code rows based on Compliance status Yes/No/NA
If CCtrl.Checked Then
For Each aCC In CCtrl.Range.Cells(1).Range.ContentControls
If aCC.Tag <> CCtrl.Tag Then aCC.Checked = False
Next aCC
Select Case CCtrl.Tag
Case "Yes"
lngColour = wdGreen
Case "No"
lngColour = wdRed
Case "NA"
lngColour = wdDarkYellow
' Case "MASTER"
' lngColour = wdGray50
' Case Else
' lngColour = wdAuto
End Select
CCtrl.Range.Font.ColorIndex = lngColour
Set aCC = CCtrl.Range.Rows(1).Range.ContentControls(1)
aCC.LockContents = False
aCC.Range.Font.ColorIndex = lngColour
aCC.LockContents = True
End If
End If
End Sub
Last edited by mj_sklarWRK; 02-14-2024 at 01:28 PM. Reason: I found the solution to my question; updating post with the answer. |
| 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 "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 |