![]() |
|
![]() |
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
![]()
I have a Word document with 11 yes or no questions, some of which have subquestions using ContentControl Checkboxes. The goal is to restrict editing except for ContentControls, and to send the document to clients. When I lock the document to send to a client, I want them to check the first answer yes or no, and if they answer no the subquestions are no longer relevant and I don't want them to be visible. I've found a way to hide the subquestions with a heading which is collapsed by default but when the document is locked moving through the ContentControls sequentially expands the headings automatically. I'm trying to write a macro to remove the subquestion Checkboxes if the answer to the main question is no. It would also be nice to expand the heading if the answer is yes because some of the questions don't have ContentControls in the subquestions. I have little/no experience with VBA and I'm sure it shows in my code, but any help would be much appreciated. Thanks!
Sub DeleteCheckboxes() Dim aCC As ContentControls Dim doc As Word.Document Dim q1ifyes As Style Dim q1nobox As ContentControl Dim q1yesbox As ContentControl Dim q1byes As ContentControl Dim q1bno As ContentControl Dim q1cyes As ContentControl Dim q1cno As ContentControl Set doc = ActiveDocument Set q1yesbox = doc.SelectContentControlsByTag("q1_yesbox").Item(1 ) Set q1nobox = doc.SelectContentControlsByTag("q1_nobox").Item(1) Set q1byes = doc.SelectContentControlsByTag("q1b_yesbox").Item( 1) Set q1bno = doc.SelectContentControlsByTag("q1b_nobox").Item(1 ) Set q1cyes = doc.SelectContentControlsByTag("q1c_yesbox").Item( 1) Set q1cno = doc.SelectContentControlsByTag("q1c_nobox").Item(1 ) q1yesbox.Type = wdContentControlCheckBox q1byes.Type = wdContentControlCheckBox q1bno.Type = wdContentControlCheckBox q1cyes.Type = wdContentControlCheckBox q1cno.Type = wdContentControlCheckBox For Each q1nobox In ActiveDocument.ContentControls If q1nobox.Checked Then q1byes.Delete (True) q1bno.Delete (True) q1cyes.Delete (True) q1cno.Delete (True) End If Next q1nobox On Error Resume Next End Sub |
#2
|
||||
|
||||
![]()
I wouldn't do this with collapsed subheadings. Instead I would place the subquestions into a rich text Content Control and then hide/show that range according to the answer they give. This code and attached document shows how I've made it so you don't need to edit the code to add more sections - just set up the CC title or tag properties in matching pairs.
Code:
Private Sub Document_ContentControlOnExit(ByVal aCC As ContentControl, Cancel As Boolean) Dim aCCont As ContentControl If aCC.Tag = "Has Subquestions" Then For Each aCCont In ActiveDocument.SelectContentControlsByTitle(aCC.Title & " Subquestions") aCCont.Range.Font.Hidden = Not aCC.Checked Next aCCont End If End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
![]()
This worked! Thank you so much!
|
![]() |
Tags |
checkboxes, contentcontrols |
|
![]() |
||||
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 |
Add / Sum checked Checkboxes labelled 1, 2, 3, etc. in Word Table - Need Macro? | klearazkrystal | Word VBA | 7 | 03-31-2019 11:50 PM |
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 |
Wanting to use checkboxes etc in a TOC to delete specific pages in a 300 page document | Tammy | Word | 4 | 10-11-2016 05:53 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 |