Hi - apologies if I'm misunderstanding as I'm new to this but I am just wanting to show or hide bookmark text in a Word document based on a checkbox being ticked on or off.
I have tried:
Private Sub Document_Open() ' This subroutine runs when the Word document is opened
' It ensures that the text linked to checkboxes is hidden by default
HideTextBasedOnCheckbox
End Sub
Private Sub CheckBox1_Click()
' This subroutine is linked to the checkbox's click event
HideTextBasedOnCheckbox
End Sub
Private Sub HideTextBasedOnCheckbox()
' This subroutine checks the state of the checkbox and shows/hides text accordingly
Dim cb As CheckBox
Set cb = ActiveDocument.FormFields("CheckBox1").CheckBox
If cb.Value = True Then
' If the checkbox is ticked, show the text
ActiveDocument.Bookmarks("TextToDisplay").Range.Font.Hidden = False
MsgBox "The checkbox is ticked!", vbInformation
Else
' If the checkbox is not ticked, hide the text
ActiveDocument.Bookmarks("TextToDisplay").Range.Font.Hidden = True
End If
End Sub
Is there something wrong with the above code?
Thanks
T