PDA

View Full Version : Showing / Hiding bookmarked table when checkbox is checked / unchecked



DGD
01-16-2016, 12:19 PM
Hi all, sorry for the basic question here... but I really need some help. I've been trying to automate a document (form really). I have six checkboxes towards the beginning of my Word document. When a user checks one of these box, I would like the associated bookmarked table to unhide (and hide by default). This form is used to determine the impact of a change to a product. So, basically, if there was a change to software, the user could select the software checkbox and labeling checkbox (because the associated instructions would need to be updated). This would then unhide the table of questions for software and labeling (the remaining tables would still be hidden). I hope this is enough detail. You can see the attached word document for more detail.

I've searched through the forums, but have not found the information needed. I've also tried sample code from the internet... but am still having no luck (I can get it to work sometimes, but when you check the box and then uncheck it the associated bookmark doesn't hide again --- frustrating!).

Any help would be greatly appreciated.

Thanks.

Dave

DGD
01-17-2016, 06:37 PM
Hi all,

Is there a better way to code this?


Sub HideTable()
ActiveDocument.Tables(5).Range.Font.Hidden = True
End Sub


Sub ShowTable()
ActiveDocument.Tables(5).Range.Font.Hidden = False
End Sub


Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
If (ContentControl.Title = "CheckBox1" And ContentControl.Checked = False) Then
HideTable
ElseIf (ContentControl.Title = "CheckBox1" And ContentControl.Checked = True) Then
ShowTable
End If
End Sub


Thanks.

Dave

gmayor
01-17-2016, 10:38 PM
Not really. Though I would also use similar code in a ContentControlOnExit macro. The code will have to be in the document which must be macro enabled.

gmaxey
01-18-2016, 05:39 AM
Hidden tables may or may not be hidden in your user's documents. They have control over font attributes not you. Instead of changing font attribute of a table, why don't you change content of another rich text control. Create a building block of your table. If the box is checked, fill the rich text CC the table building block, if not fill it with a zero width space.

Also use this construction in your CC Exit event:

Select Case ContentControl.Title
Case "Checkbox1"
If ContentControl.Check Then

Else

End If
Case "CheckBox2"

Case "Checkbox .... 500"

End Select

DGD
01-25-2016, 08:55 AM
Thanks Greg... I like the idea of placing a building block in a rich text cc based on the checkbox selected. What would the code look like (for the insertion of a building block into a rich text cc)?

Thanks again for your help... and sorry again for the basic questions. I've d/l'd Visual Studio Express and am running through some training videos... also purchased a book to help me with the coding. Just need some time to learn VB so I don't have to ask these types of questions.

DGD