dimanche 18 juin 2017

VBA code to change text when checkbox is selected in Word 2013

I have this:

☐ text text text text

The checkbox is named 'ToDo', and the text appears in a bookmark named 'bookmarkToDo'.

Select the checkbox, and the text becomes struckout:

text text text text

Select the checkbox again and the text returns to normal.

The VBA code to do this is:

Private Sub ToDo_Change()
Call ShowHideBookmarkToDo
End Sub

Sub ShowHideBookmarkToDo()
If ToDo.Value = True Then
    ActiveDocument.Bookmarks("bookmarkToDo").Range.Font.StrikeThrough = False
Else
    ActiveDocument.Bookmarks("bookmarkToDo").Range.Font.StrikeThrough = True
End If
End Sub

I need now to replace the bookmark and instead use the newer content controls.

I guess I need to replace 'Bookmarks' with something similar to 'ContentControl.Tag("ToDo")'. I've found no clear instructions online in how to construct the necessary line of VBA code, and the various code constructs I've tried do not work. Any help is appreciated.




Aucun commentaire:

Enregistrer un commentaire