Results 1 to 3 of 3

Thread: How can I add multiple items to Word drop downs without keying each item in?

  1. #1
    VBAX Newbie
    Jun 2018

    How can I add multiple items to Word drop downs without keying each item in?


    So my goal is to enter as many names as I want at once into the Word drop downs created in the Design Mode under the Developer tab. As it is currently, you can only enter one name at a time. I have over 300 names I need to add to multiple drop downs on multiple documents so I have looked for a Macro solution.

    I found this solution linked here with the following code:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim oCC As ContentControl
    Dim oRng As Word.Range
    Dim lngIndex As Long
    'Assumes your dropdown is named DDList.
    Set oCC = ActiveDocument.SelectContentControlsByTitle("DDList").Item(1)
    Set oRng = Selection.Range
    'Assumes that you have a list selected in the document _
    and each list entry starts a new paragraph.
    For lngIndex = 1 To oRng.Paragraphs.Count
      oCC.DropdownListEntries.Add Left(oRng.Paragraphs(lngIndex).Range.Text, _
                             Len(oRng.Paragraphs(lngIndex).Range.Text) - 1)
    Next lngIndex
    End Sub
    When I first used this I didn't realize I had to title the drop down with "DDList" (or whatever I want to call it; I have different name lists for different drop downs so I assume I can make a bunch of different ones with different names). Anyway, after doing that I was able to run the macro successfully and I was ecstatic. However after trying to run it on multiple drop downs at once it doesn't work. I asked the creator of the code if there was something wrong or if there was a work around I can do and he replied:

    "The code works with the first titled “DDList” If you have more than one titled DDList then you would have to used .Item(2), .Item(3) etc. Or if your CCs have different titles then change “DDList” in code above to the appropriate title as you process each one."

    I have no idea what this means or how I can use it to do what I want it to do. I am brand new to VBA's/Macros, I didn't even know they existed until this. Luckily google exists but I still can't seem to figure out what he means and what I should do to solve my problem. I'm hoping you guys can help me.

    Some side notes: I'm using Word 2016 on Windows 10

  2. #2
    You could use the content control list editor option of and copy and paste the list of names into the list editor - one per line.

    With regard to your specific question, the quoted code processes the first content control with the title "DDList"

    Set oCC = ActiveDocument.SelectContentControlsByTitle("DDList").Item(1)

    i.e. Item(1)

    Content control titles can be duplicated (though this can create confusion if the controls are not mapped and copied). If you have duplicated titles e.g. You copy the first control and paste it elsewhere in the document, they both have the same title and content but remain independent from one another, however the code you gave quoted will only process the first one.

    If you want to process (say) the second one using a macro, change Item(1) to Item(2)

    Clearly in such circumstances it would be better to have different title (or tags) for the controls and avoid that confusion. To that end includes a utility that can step through the controls and allow you to edit their titles and tags.

    Mapped controls behave as one control so when copied as above whatever is selected in one is also selected in the rest. This can be useful for repeating values throughout the document.
    Graham Mayor - MS MVP (Word)
    Visit my web site for more programming tips and ready made processes

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Jul 2008
    Cross-posted at:
    Please read VBA Express' policy on Cross-Posting in item 3 of the rules:
    Paul Edstein
    [MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts