PDA

View Full Version : [SOLVED:] Use Drop-Down List Content Control to Populate Bookmark (multiselect)



eazyt33
12-02-2022, 08:52 AM
Hello,

I have programmed in VBA for years but mostly in Excel. Right now, I am making a .DOTX or template file in Word and I have a Drop-Down List (content control style) and I am attempting to give users the ability to select items from the list and have the selections populate to preselected locations in the Word Document. Does that make sense?

My main issue is that I have no working knowledge of the vba behind these "content controls" I just spent hours reading through literature about them but can't quite wrap my head around it. Below is my really bad attempt at what I am trying but should shed some light on where I am going with this. Basically, I would like the user to "activate" the drop down, click the item them want, and it will populate directly below (using a bookmark) in the word document. If they select another item, it will in some way populate with the first item or move on to the next line below the first entry.

I know this is not great but I think it will guide a better understanding of what I am trying to accomplish. Hopefully it is possible and thanks in advance.


Sub DDmulti()
Dim doc As Word.Document
Dim ccLB As Word.ContentControl
Set doc = ActiveDocument
Set ccLB = doc.SelectContentControlsByTitle("lb").Item(1)
If ccLB.selected Then
Selection.GoTo What:=wdGoToBookmark, Name:="lb"
With Selection
Selection.Add
End With
End If
End Sub

macropod
12-02-2022, 01:17 PM
The code you've posted isn't anything like what one would use for populating a document from a dropdown content control selection. See, for example: [SOLVED] Dependent Drop Down Lists in Word (vbaexpress.com) (http://www.vbaexpress.com/forum/showthread.php?64990-Dependent-Drop-Down-Lists-in-Word&highlight=CCtrl), where there is code that does much more than what you're asking.

See also:

Dependent Text Content Controls
https://www.msofficeforums.com/word-vba/16498-multiple-entries-dropdown-lists.html#post46903
and, for different elements from a selected item to be output to different content controls:
https://www.msofficeforums.com/word-vba/16498-multiple-entries-dropdown-lists-5.html#post120392


Dependent Dropdown Content Controls
https://www.msofficeforums.com/word-vba/24661-help-cascading-dropdown-list.html#post77762
and, for multiple levels of dependency:
https://www.msofficeforums.com/word-vba/24661-help-cascading-dropdown-list.html#post132696


Cascading Dropdown Content Controls
https://www.msofficeforums.com/word-vba/29617-creating-reducing-drop-down-list.html#post94603


Content Control Conditional Formatting
https://www.msofficeforums.com/word-vba/16505-change-color-according-dropdown-selection.html#post47254


Dropdown Content Control Population from Excel
https://www.msofficeforums.com/word-vba/16330-how-import-list-excel-into-drop-down.html#post46287

Creating and Tallying Mutually-exclusive Checkboxes
https://www.msofficeforums.com/word-tables/12335-assigning-values-content-control-checkboxes-calculating-results.html#post33489
https://www.msofficeforums.com/word-tables/33248-content-control-checkbox-calculations.html#post107008


Adding a New Row to a Table:
https://www.msofficeforums.com/word-vba/27809-code-add-new-row-table.html#post87989
https://www.msofficeforums.com/word-vba/13955-macro-add-row-table-word-form.html#post38461
https://www.msofficeforums.com/word-vba/43603-multiple-dependent-dropdown-lists-table-add-new.html#post145675

I note that your post title refers to 'multiselect'. Neither dropdown nor combobox content controls allow more than one item to be selected at a time.

Chas Kenyon
12-04-2022, 05:44 PM
Instead of a vba solution, consider simply using a mapped content control. The choice will be reflected in each copy of the control.



Mapped Content Controls by Greg Maxey
(http://gregmaxey.com/word_tip_pages/mapped_content_controls.html)
(http://gregmaxey.com/word_tip_pages/mapped_content_controls.html)Insert Content Control Add-In by Graham Mayor, MVP (https://www.gmayor.com/insert_content_control_addin.htm)
Walkthrough: Bind content controls to custom XML parts
(https://docs.microsoft.com/en-us/visualstudio/vsto/walkthrough-binding-content-controls-to-custom-xml-parts?view=vs-2019)
Repeat Text With Mapped Content Controls (https://www.youtube.com/watch?v=OtFhIqK0gec) by Laura Townsend (video)