#1
|
|||
|
|||
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 What am i doing wrong? Can somebody help me with this? |
#2
|
|||
|
|||
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 |
#3
|
|||
|
|||
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. |
#4
|
||||
|
||||
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 |
#5
|
|||
|
|||
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? |
#6
|
||||
|
||||
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 |
|
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 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 |