Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 11-03-2023, 04:39 PM
Guessed's Avatar
Guessed Guessed is offline VBA to show/hide checkboxes- always showing bookmark Windows 10 VBA to show/hide checkboxes- always showing bookmark 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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
UserForm with checkboxes that hide/show bookmarked text in document dohertym Word VBA 4 05-16-2022 09:48 PM
Checkbox - toggle hide/unhide other checkboxes and their texts Basse Word VBA 2 05-11-2022 10:43 PM
Hide one bookmark when Two checkboxes are checked AVarg123 Word VBA 4 04-01-2022 06:21 PM
REf Fields show Bookmark whole cell when Bookmark is created by code. pmcpowell Word VBA 2 11-16-2019 07:05 PM
Bookmark will not show/hide based on CC Checkbox lord_kaiser Word VBA 1 04-17-2018 01:19 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:39 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft