![]() |
|
![]() |
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
![]()
Thanks in advance for any help!
In the document I'm creating I am hoping to autopopulate 2 or more text content controls with differing values based on one dropdown option. e.g: dropdown "Choose size" has 2 options: 'Large' and 'Small'. when a size is chosen I would like a value for its height to populate in textbox 'Height' and a separate/different value for its width to populate in textbox 'Width' Is this do-able the way I have mentioned above? I know how to populate when only one value is required. If there is an easier/better way of completing this please point me in the right direction! |
#2
|
||||
|
||||
![]()
If you use a ListBox content control titled 'Size' then the following macro in the ThisDocument module of the document/template will populate the two text controls with the values shown, when you click out of the list box.
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim oCC As ContentControl If ContentControl.Title = "Size" Then If ContentControl.ShowingPlaceholderText = False Then Select Case ContentControl.Range.Text Case "Large" Set oCC = ActiveDocument.SelectContentControlsByTitle("Height").Item(1) oCC.Range.Text = "123 cm" Set oCC = ActiveDocument.SelectContentControlsByTitle("Width").Item(1) oCC.Range.Text = "234 cm" Case "Small" Set oCC = ActiveDocument.SelectContentControlsByTitle("Height").Item(1) oCC.Range.Text = "25 cm" Set oCC = ActiveDocument.SelectContentControlsByTitle("Width").Item(1) oCC.Range.Text = "36 cm" End Select Else Set oCC = ActiveDocument.SelectContentControlsByTitle("Height").Item(1) oCC.Range.Text = "" Set oCC = ActiveDocument.SelectContentControlsByTitle("Width").Item(1) oCC.Range.Text = "" End If End If Set oCC = Nothing End Sub You may find Insert Content Control Add-In useful.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
||||
|
||||
![]()
You can do this with a series of dropdown content controls all mapped to the same xml field if you didn't want to use a macro-enabled method.
For each CC, each dropdown entry has a Display Name and a Value. If the value matches the same value chosen in a different CC then the displayed name will change accordingly.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#4
|
|||
|
|||
![]()
thanks gmayor! this works great for what I want.
Is there a way to show the test on change rather than on exit? Also how would I repeat this for another set of listbox/text? i.e. another separate listbox with multiple values to show in different text boxes on the same document? |
#5
|
||||
|
||||
![]()
As long as the content control titles are different, simply repeat the IF condition for the second list box & text boxes.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Clear all content controls (Text, dropdown) AND change option button values to FALSE in MS Word Form | Janet D | Word VBA | 7 | 01-14-2023 02:36 AM |
How to use content controls to populate text throughout the same document? | WordUnknown | Word | 6 | 11-01-2022 11:08 AM |
![]() |
lmoir87 | Word VBA | 15 | 05-27-2022 04:22 PM |
![]() |
Frantic | Word VBA | 2 | 01-24-2015 04:54 PM |
![]() |
john s. | Word VBA | 1 | 02-21-2014 02:14 PM |