How to run a VBA macro by clicking the "Word 2010" checkbox?

I want to run a macro when I check the box in Word 2010 .

Please note: I do not want the "Legacy Forms" or "ActiveX" checkbox! . They only work in some protected document mode and look ugly, but I need new ones that can be selected and not selected only when you write the document, and which look much nicer to me.

I know that with legacy forms, you can directly insert a macro when entering a form element and one to leave it, and you can catch an event in VBA, for example

Sub CheckboxXY_Click() 

But this does not work with Word 2010 flags, even when I give them a description and a tag name.

Repeat : these are the forms I want to use (just in case someone advises me to use Legacy):

Word 2010 checkbox

And how they look in the document (with mouse hover):

enter image description here

I can’t believe that I was the first to try this ...

+6
source share
1 answer

Make sure you go to the document in your VBA project and select "ContentControlOnEnter"

You will need to specify which content content you need using something like ContentControl.Title to indicate which checkbox activates part of your code, as shown in the example below. (I also added code to make sure the checkbox is checked in the example)

 Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl) If (ContentControl.Title = "Checkbox1" And ContentControl.Checked = True) Then MsgBox "YAAY", vbOKOnly, "Test1" End If If (ContentControl.Title = "Checkbox2" And ContentControl.Checked = True) Then MsgBox "BOOO", vbOKOnly, "Test2!" End If End Sub 
+3
source

All Articles