Content Control Check Box

Am I able to set up a Check Box Content Control so that when it is checked a piece of text is inserted at a specific point elsewhere in the document?
Answer
Answer

You can use a 'ContentControlOnExit' macro in the document's 'ThisDocument' module for this. the following code shows how you might implement this with a checkbox titled 'MyCheckBox' and a bookmark named 'Destination' in the document.

 

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
  If ContentControl.Title = "MyCheckBox" Then
    If ContentControl.Checked = True Then
      Call UpdateBookmark("Destination", "Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus." & vbCr)
    Else
      Call UpdateBookmark("Destination", "")
    End If
  End If
End Sub

 

Sub UpdateBookmark(BmkNm As String, NewTxt As String)
Dim BmkRng As Range
With ActiveDocument
  If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    BmkRng.Text = NewTxt
    .Bookmarks.Add BmkNm, BmkRng
  End If
End With
Set BmkRng = Nothing
End Sub

 

Note that, if the checkbox is unchecked after checking, the inserted content is deleted.

Cheers
Paul Edstein
(Fmr MS MVP - Word)

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 224 Applies to: