#1
|
|||
|
|||
Use VBA to show text when content control check box is checked
I am trying to set a word document up, so that when the user checks a content control "Yes" check box, pre-defined text that asks a follow up question will appear below the original question. I used an example code I found online but when I insert the code into my document, it does not work. I have named the checkboxes, as they did in the example and have insert field code where the text should appear and also set up custom document properties, however, it still does not work. Can anyone provide some guidance on this? I have attached the file, so that you can see what I am referencing. It is on page 9 of the document, and I have highlighted the four areas I am referencing. If the user selects No, there is no text that appears. They will just proceed to the next question. |
#2
|
||||
|
||||
It would be a start if you didn't have multiple checkboxes each named Checkbox1 or Checkbox2. They need to be uniquely named for the type of code event you are planning to work.
Then you will need to adjust your main code if you want the other checkbox pairs to work in a similar fashion. Your checkbox entered is in the wrong Case selection group. It should be in the main group relating to CC Code:
Case "Checkbox1" If CC.Checked = True Then ActiveDocument.SelectContentControlsByTitle("Checkbox2").Item(1).Checked = False ActiveDocument.CustomDocumentProperties("Chk1").Value = 1 ActiveDocument.CustomDocumentProperties("Chk2").Value = 0 Else ActiveDocument.SelectContentControlsByTitle("Checkbox2").Item(1).Checked = True ActiveDocument.CustomDocumentProperties("Chk1").Value = 0 ActiveDocument.CustomDocumentProperties("Chk2").Value = 1 End If ActiveDocument.Fields.Update Case "Checkbox2" If CC.Checked = True Then ActiveDocument.SelectContentControlsByTitle("Checkbox1").Item(1).Checked = False ActiveDocument.CustomDocumentProperties("Chk2").Value = 1 ActiveDocument.CustomDocumentProperties("Chk1").Value = 0 Else ActiveDocument.SelectContentControlsByTitle("Checkbox1").Item(1).Checked = True ActiveDocument.CustomDocumentProperties("Chk2").Value = 0 ActiveDocument.CustomDocumentProperties("Chk1").Value = 1 End If ActiveDocument.Fields.Update End Select End Sub You may find Insert Content Control Add-In useful as a means of editing the controls (including the list box to remove the unwanted placeholder text). Note that you don't need the module relating to Word 2007 compatibility. Word 2007 is not compatible with check box content controls, that were introduced with Word 2010.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com Last edited by gmayor; 08-19-2023 at 10:59 PM. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Check box content control to show text when checked | Strogg | Word | 3 | 02-10-2019 11:45 AM |
VBA in Word 2010 to show certain text only when a YES checkbox is checked | kdsim | Word VBA | 0 | 05-16-2018 05:16 AM |
Check Box Content Control when checked users are presented with an option | cryder | Word | 0 | 01-07-2016 05:11 AM |
how to show total of check boxes checked | worder | Word | 16 | 03-10-2014 05:07 PM |
Word2010 check boxes and plain text content control boxes in same table | fcsungard | Word | 5 | 06-01-2012 01:16 AM |