#1
|
|||
|
|||
auto-populating dropdown list
Hi friends!
I would be grateful if you could help me with the VBA code. I would like to have programmed behavior of a drop-down list, let's call it "Test", the content of which changes depending on the selection from the list. Let me explain. Initially, the list has items "A", "B" and "C". When "A" is selected, the drop-down list is automatically populated with options "A.I", "A.II" and "A.III". If "A.I" is selected, the list is automatically populated with the new entries "A.I.a", "A.I.b" and "A.I.c". If "A.I.a" is selected, the list is again automatically populated with the new entries "A.I.a.1", "A.I.a.2" and "A.I.a.3". All possible combinations should be available, e.g. "A.III.a.3" "C.II.a.1" "B.I.c.3", etc. Is this realistic? |
#2
|
|||
|
|||
So if "A" is selected and the list items change from A, B, C to A.I, A.II and A.III, what is supposed to happen to the initially selected value "A" that is displayed?
Perhaps something like this: Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim lngIndex As Long Select Case ContentControl.Title Case "Test" For lngIndex = ContentControl.DropdownListEntries.Count To 2 Step -1 ContentControl.DropdownListEntries(lngIndex).Delete Next Select Case ContentControl.Range.Text Case "A" ContentControl.DropdownListEntries.Add "A.I", "A.I" ContentControl.DropdownListEntries.Add "A.II", "A.II" ContentControl.DropdownListEntries.Add "A.III", "A.III" Case "A.I" ContentControl.DropdownListEntries.Add "A.I.a", "A.I.a" ContentControl.DropdownListEntries.Add "A.I.b", "A.I.b" ContentControl.DropdownListEntries.Add "A.I.c", "A.I.c" Case "B" ContentControl.DropdownListEntries.Add "B.I", "B.I" ContentControl.DropdownListEntries.Add "B.II", "B.II" ContentControl.DropdownListEntries.Add "B.III", "B.III" Case "C" ContentControl.DropdownListEntries.Add "C.I", "C.I" ContentControl.DropdownListEntries.Add "C.II", "C.II" ContentControl.DropdownListEntries.Add "C.III", "C.III" End Select End Select End Sub |
#3
|
|||
|
|||
Dear Gregory,
Thank you very much for your help. You got it right and offered a workable solution. One question. To change the displayed value from the list and run the macro further, you have to make four clicks (1st to activate the CC drop down list, 2nd to activate the list, 3rd to activate the value in the list, 4th outside the CC to accept the new selected value). While not critical, is there any way to get rid of the 4th click? I mean, to make Word realize that after the 3rd click, the value is already selected, and continue the macro from there. |
Tags |
auto fill, content control events, dropdown list |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Auto-populating tables with 3 different conditions | Deichgraf | Excel | 4 | 02-07-2023 08:58 AM |
Auto-populating a word document | csmall86 | Word | 1 | 12-20-2019 01:54 PM |
Auto populate a text field based on Content Control Dropdown List | matthias92701 | Word VBA | 2 | 05-02-2019 03:54 PM |
UserForm Dropdown List Not Populating | highrise955 | Word VBA | 14 | 04-10-2016 12:10 PM |
Need help populating dropdown box | antztaylor | Word | 3 | 11-06-2012 05:46 PM |