Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-30-2022, 04:22 PM
AVarg123 AVarg123 is offline Hide one bookmark when Two checkboxes are checked Windows 10 Hide one bookmark when Two checkboxes are checked Office 2016
Novice
Hide one bookmark when Two checkboxes are checked
 
Join Date: Dec 2021
Posts: 15
AVarg123 is on a distinguished road
Default Hide one bookmark when Two checkboxes are checked


Hello, How can I hide a bookmark when two checkboxes are checked. I have checkbox1 and checkbox2. If both are checked then the bookmark "test" should be hidden. How can I do this using word VBA? Really appreciate any help. Thank you!
Reply With Quote
  #2  
Old 03-30-2022, 09:38 PM
Guessed's Avatar
Guessed Guessed is offline Hide one bookmark when Two checkboxes are checked Windows 10 Hide one bookmark when Two checkboxes are checked Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,159
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

What type of checkbox are you using?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 03-31-2022, 10:54 AM
AVarg123 AVarg123 is offline Hide one bookmark when Two checkboxes are checked Windows 10 Hide one bookmark when Two checkboxes are checked Office 2016
Novice
Hide one bookmark when Two checkboxes are checked
 
Join Date: Dec 2021
Posts: 15
AVarg123 is on a distinguished road
Default

ActiveX Checkbox Control
Reply With Quote
  #4  
Old 03-31-2022, 08:51 PM
gmayor's Avatar
gmayor gmayor is offline Hide one bookmark when Two checkboxes are checked Windows 10 Hide one bookmark when Two checkboxes are checked Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following will do that, however you should be aware that if the font is hidden it can easily be un-hidden by anyone viewing the document in Word format. Change BMName to the name of the bookmark.
Code:
Private Sub CheckBox1_Click()
    ActiveWindow.View.ShowHiddenText = False
    If CheckBox1.Value = True And CheckBox2.Value = True Then
        ActiveDocument.Bookmarks("BMName").Range.Font.Hidden = True
    Else
        ActiveDocument.Bookmarks("BMName").Range.Font.Hidden = False
    End If
End Sub

Private Sub CheckBox2_Click()
    ActiveWindow.View.ShowHiddenText = False
    If CheckBox1.Value = True And CheckBox2.Value = True Then
        ActiveDocument.Bookmarks("BMName").Range.Font.Hidden = True
    Else
        ActiveDocument.Bookmarks("BMName").Range.Font.Hidden = False
    End If
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 04-01-2022, 06:21 PM
Guessed's Avatar
Guessed Guessed is offline Hide one bookmark when Two checkboxes are checked Windows 10 Hide one bookmark when Two checkboxes are checked Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,159
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

Graham gave you the solution already.

Note that there is a gotcha with the .ShowHiddenText - if the user has ShowAll then it doesn't matter about the showhiddentext. To deal with that and make the code a bit shorter...
Code:
Private Sub CheckBox1_Click()
  ActiveWindow.View.ShowHiddenText = False
  ActiveWindow.View.ShowAll = False
  ActiveDocument.Bookmarks("BMName").Range.Font.Hidden = CheckBox1.Value And CheckBox2.Value
End Sub

Private Sub CheckBox2_Click()
  CheckBox1_Click
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add / Sum checked Checkboxes labelled 1, 2, 3, etc. in Word Table - Need Macro? klearazkrystal Word VBA 7 03-31-2019 11:50 PM
Bookmark will not show/hide based on CC Checkbox lord_kaiser Word VBA 1 04-17-2018 01:19 AM
Need Macro to select Checkbox after two boxes are checked in a series of checkboxes rsaini Word VBA 0 01-16-2018 11:57 AM
Hide one bookmark when Two checkboxes are checked Hide error message from missing bookmark lodi123 Word 2 03-28-2017 11:24 PM
Checkboxes are unchecked in Listbox that were checked off before.How can I stop this? Rochelle711 Excel Programming 0 06-22-2014 06:16 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:25 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