mardi 5 juin 2018

Run a macro when any checkbox is hit in Word

I'd like to fire generic code for an unknown number of checkboxes to change the formatting style of a line. I have multiple lines that lead with a checkbox and I want a check to set the line to normal and an uncheck to set the format to Heading 2.

Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)

If ContentControl.Checked = True Then
    Selection.Style = ActiveDocument.Styles("Normal")
ElseIf contextcontrol.Checked = False Then
    Selection.Style = ActiveDocument.Styles("Heading 2")
End If

End Sub

Checking a box sets the cursor on that line so I am hoping this strategy will work. I've never used vba in Word so I think I'm doing something wrong just in getting the code to fire?




Aucun commentaire:

Enregistrer un commentaire