View Single Post
 
Old 11-03-2023, 04:39 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The code is only run when you click in a checkbox and it doesn't automatically execute at specific times (like at document open) because you haven't coded for that.

I suggest you set up the document differently so that the coding becomes far simpler. First, get rid of the old school checkboxes and replace them with Checkbox Content Controls. With each of these checkbox CCs, set the Title property to match the name of the bookmark you want to hide with it. Then paste this following code into your ThisDocument module.
Code:
Private Sub Document_ContentControlOnExit(ByVal myContentControl As ContentControl, Cancel As Boolean)
  If myContentControl.Type = wdContentControlCheckBox Then Document_Open
End Sub

Private Sub Document_Open()
  Dim aCC As ContentControl
  For Each aCC In ActiveDocument.ContentControls
    If aCC.Type = wdContentControlCheckBox Then
      If ActiveDocument.Bookmarks.Exists(aCC.Title) Then
        ActiveDocument.Bookmarks(aCC.Title).Range.Font.Hidden = Not aCC.Checked
      End If
    End If
  Next aCC
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote