Thread: [Solved] Content Control Checkboxes
View Single Post
 
Old 01-03-2017, 10:23 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
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 ofgmayor has much to be proud of
Default

You have to actually enter the content control from outside the control in order for the ContentControlOnEnter sub to fire. It doesn't operate on simply toggling the control. Thus the following should demonstrate.

Code:
Option Explicit

Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
    Select Case ContentControl.Title
        Case "ccHW"
            If ContentControl.Checked Then
                FillBM "HW", "This is the content of bookmark HW"
            Else
                FillBM "HW", ""
            End If
        Case "ccCS"
            If ContentControl.Checked Then
                FillBM "CS", "This is the content of bookmark CS"
            Else
                FillBM "CS", ""
            End If
    End Select
End Sub

Private Sub FillBM(strBMName As String, strValue As String)
'Graham Mayor - http://www.gmayor.com
Dim oRng As Range
    With ActiveDocument
        On Error GoTo lbl_Exit
        Set oRng = .Bookmarks(strBMName).Range
        oRng.Text = strValue
        oRng.Bookmarks.Add strBMName
    End With
lbl_Exit:
    Set oRng = 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