#1
|
|||
|
|||
Creating drop down list content control with "if" conditions
Hello, I need to create a drop down list content control box with a simple condition.
My drop down contains 2 options If the first option is chosen, I need an additional plain text content control box to appear beneath If the second option is chosen, nothing would happen How do I achieve this? Thank you. |
#2
|
||||
|
||||
What are you like with macros? If you do a search in this forum for ContentControlOnExit you will find lots of examples of code that runs automatically when you change a CC. Then it is a case of showing/hiding the paragraph/row where the other CC sits.
If you don't know how to adapt that code, you should post a sample document showing what you have.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Creating drop down list content control with "if" conditions
Macros will be a stretch for me, but I'll look at the ContentControlOnExit posts and do my best.
I've attached a simple example of my sheet here. If user selects "yes" in initial control box, I want the text box to open. If user selects "no", then nothing happens. I need this to carry over to an Outlook message. I'm using content controls in outgoing messaging using Quick Parts. Will the macros copy over to Outlook? I appreciate any help. Thanks! |
#4
|
||||
|
||||
OK, do a SaveAs on that file and change the type to docm
Set the Title Property of the first CC to 'Interested" Set the Title Property of the second CC to "Explain" Add the following macro to the ThisDocument module in the file Code:
Private Sub Document_ContentControlOnExit(ByVal thisCC As ContentControl, Cancel As Boolean) Dim aCC As ContentControl, bHide As Boolean If thisCC.Title = "Interested" Then bHide = thisCC.Range.Text = "No" 'bHide = Not thisCC.Range.Text = "Yes" 'this alternative treats a non-selection differently End If 'Change the hidden property on the dependent CC paragraph For Each aCC In ActiveDocument.SelectContentControlsByTitle("Explain") aCC.Range.Paragraphs(1).Range.Font.Hidden = bHide Next aCC 'Ensure hidden text is not visible on screen With ActiveWindow.View .ShowHiddenText = False .ShowAll = False End With End Sub Note that I put two alternatives for bHide in the code. You can enable or disable these lines by adding/removing the ' from the start. The difference is how it treats the top option ie blank.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
I thought I had it working, but running into issues.
My document attached. I insert the Macro and run, but it isn't working as intended. Appreciate any help to indicate what I'm doing wrong. Much appreciated. |
#6
|
|||
|
|||
Here is the file
|
#7
|
||||
|
||||
You put the code in the wrong module. Take it out of Module1 and put it into ThisDocument.
The module is 'special' as having the code there allows it to be fired off by document events rather than needing you to tell Word when to run it.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#8
|
|||
|
|||
Perfect. Many thanks for walking me through it!
|
Tags |
conditions, content control |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Assigning Macro to Drop Down list Content Control | aussiew | Word VBA | 5 | 03-10-2019 02:55 PM |
Build paragraphs based on selecting "yes" from a content control | jeffreybrown | Word VBA | 8 | 11-07-2018 04:02 PM |
How to "hard link" two adjacent cells to a data validation drop down list? | Geza59 | Excel | 10 | 10-19-2012 11:56 AM |
How to edit the "Format" and the "show level" of an EXISTING table of content? | Jamal NUMAN | Word | 2 | 08-14-2011 10:46 AM |
How to choose a "List" for certain "Heading" from "Modify" tool? | Jamal NUMAN | Word | 2 | 07-03-2011 03:11 AM |