Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-12-2022, 07:38 AM
Strange Strange is offline Hide a bookmark with a ContentControlCheckBox Windows 10 Hide a bookmark with a ContentControlCheckBox Office 2019
Novice
Hide a bookmark with a ContentControlCheckBox
 
Join Date: Dec 2022
Posts: 3
Strange is on a distinguished road
Default Hide a bookmark with a ContentControlCheckBox

Hello,


I am new to MS VBA and i have a very special Question.
I am trying to hide a bookmarked text with a ContentControlCheckBox.

I tried this code:

Code:
Private Sub Document_ContentControlBeforeContentUpdate(ByVal ContentControl As ContentControl, Content As String)
      If ContentControl.Tag = "Checkbox1" Then
      If Content = "true" Then ActiveDocument.Bookmarks("Test1").Range.Font.Hidden = True
      If Content = "false" Then ActiveDocument.Bookmarks("Test1").Range.Font.Hidden = False
    End If
End Sub
But i just get an error message: Runtime error 6197: This object model error is not available in the current event.

What am i doing wrong? Can somebody help me with this?
Reply With Quote
  #2  
Old 12-12-2022, 08:07 AM
Italophile Italophile is online now Hide a bookmark with a ContentControlCheckBox Windows 11 Hide a bookmark with a ContentControlCheckBox Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

You're using the wrong event. The following works for me.

Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    If ContentControl.Tag = "Checkbox1" Then
        ActiveDocument.Bookmarks("Test1").Range.Font.Hidden = ContentControl.Checked
    End If
End Sub
Reply With Quote
  #3  
Old 12-12-2022, 12:21 PM
Strange Strange is offline Hide a bookmark with a ContentControlCheckBox Windows 10 Hide a bookmark with a ContentControlCheckBox Office 2019
Novice
Hide a bookmark with a ContentControlCheckBox
 
Join Date: Dec 2022
Posts: 3
Strange is on a distinguished road
Default

Hi Italophile!
Thank you very much, works fine with me too. So next question would be if there is any chance to run this code with opening the file. So like it would check at the start if the checkbox is already true and hides the text at the beginning.
Reply With Quote
  #4  
Old 12-12-2022, 03:56 PM
Guessed's Avatar
Guessed Guessed is offline Hide a bookmark with a ContentControlCheckBox Windows 10 Hide a bookmark with a ContentControlCheckBox Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,980
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

You will need a second macro to fire automatically as you open the document. If you have both macros in the ThisDocument module they would be...
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    If ContentControl.Tag = "Checkbox1" Then
        ActiveDocument.Bookmarks("Test1").Range.Font.Hidden = ContentControl.Checked
    End If
End Sub

Private Sub Document_Open()
  Dim aCC As ContentControl
  If ActiveDocument.SelectContentControlsByTag("Checkbox1").Count = 1 Then
    Set aCC = ActiveDocument.SelectContentControlsByTag("Checkbox1")(1)
    ActiveDocument.Bookmarks("Test1").Range.Font.Hidden = aCC.Checked
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 12-20-2022, 06:24 AM
Strange Strange is offline Hide a bookmark with a ContentControlCheckBox Windows 10 Hide a bookmark with a ContentControlCheckBox Office 2019
Novice
Hide a bookmark with a ContentControlCheckBox
 
Join Date: Dec 2022
Posts: 3
Strange is on a distinguished road
Default

Hello Guessed,
i tried your code. It workes fine but its still not works they way i want it to. I have an external software which can check and uncheck this Checkbox, but the problem i is that it ony changes the value from the checkbox.

I tried the Document_ContentControlBeforeStoreUpdate (which should work with my software) but i am just getting the error message from my first post. (Runtime error 6197: This object model error is not available in the current event.)

This ist the code i tried:

Private Sub Document_ContentControlBeforeStoreUpdate(ByVal ContentControl As ContentControl, Content As String)

If ContentControl.Tag = "Checkbox1" Then
ContentControl.Parent.Bookmarks("Test1").Range.Fon t.Bold = ContentControl.Checked
End If

End Sub

You guys maybe have a solution for me?
Reply With Quote
  #6  
Old 12-20-2022, 02:30 PM
Guessed's Avatar
Guessed Guessed is offline Hide a bookmark with a ContentControlCheckBox Windows 10 Hide a bookmark with a ContentControlCheckBox Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,980
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

Does the external software open Word to makes its change to the CC or is it modifying the zip file directly? If Word isn't opened then I wouldn't expect Word events to be able to fire.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
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
Hide a bookmark with a ContentControlCheckBox Hide error message from missing bookmark lodi123 Word 2 03-28-2017 11:24 PM
Find Bookmark, move to bookmark, execute code, repeat raymm3852 Word VBA 10 04-15-2016 06:21 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:37 AM.


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