View Single Post
 
Old 12-14-2021, 10:23 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

In the ThisDocument module of the document enter the following. Note that content controls and their contents are case sensitive so the code refers to those lower case versions of those values. The check boxes will update when you click out of the test cc.

To reduce the potential for misspelling errors, if possible, you might consider replacing the plain text CC with a listbox CC - see
https://www.gmayor.com/insert_content_control_addin.htm



Code:
Option Explicit

Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
    Select Case LCase(ContentControl.Title)
        Case Is = "cctext"
            If ContentControl.ShowingPlaceholderText = True Then
                FillCB "CCbox1", False
                FillCB "CCbox2", False
                FillCB "CCbox3", False
                FillCB "CCbox4", False
            End If
    End Select
End Sub

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    Select Case LCase(ContentControl.Title)
        Case Is = "cctext"
            FillCB "CCbox1", False
            FillCB "CCbox2", False
            FillCB "CCbox3", False
            FillCB "CCbox4", False
            If ContentControl.ShowingPlaceholderText = False Then
                If InStr(1, LCase(ContentControl.Range.Text), "test") > 0 Then
                    FillCB "CCbox1", True
                    FillCB "CCbox4", True
                End If
                If InStr(1, LCase(ContentControl.Range.Text), "actual") > 0 Then
                    FillCB "CCbox2", True
                    FillCB "CCbox3", True
                End If
            End If
        Case Else
    End Select
End Sub

Private Sub FillCB(strCCTitle As String, bValue As Boolean, Optional bLock As Boolean = False)
'Graham Mayor - https://www.gmayor.com - Last updated - 15 Dec 2021
Dim oCC As ContentControl
    On Error GoTo lbl_Exit
    For Each oCC In ActiveDocument.ContentControls
        If LCase(oCC.Title) = LCase(strCCTitle) Then
            oCC.LockContents = False
            oCC.Checked = bValue
            oCC.LockContentControl = True
            If bLock = True Then oCC.LockContents = True
            Exit For
        End If
    Next oCC
lbl_Exit:
    Set oCC = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote