How to create a long dropdown list of countries using content control dropdown list without having to type out each country as a value?

Ellis, Emma 0 Reputation points
2023-08-04T22:44:20.52+00:00

I am using a content control dropdown list in a word document since this is accessible by keyboard-only (for blind users that may not be using a mouse). How do I add a long list of countries as values without having to type out each individual value one by one?

Microsoft 365 and Office Install, redeem, activate For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Konstantinos Passadis 19,586 Reputation points MVP
    2023-08-05T00:52:05.94+00:00

    Hello @Ellis, Emma

    Welcome to Microsoft QnA!

    Although this is a Word Question i have a Solution

    Create the list in Excel

    https://gist.githubusercontent.com/kalinchernev/486393efcca01623b18d/raw/daa24c9fea66afb7d68f8d69f0c4b8eeb9406e83/countries

    1. Open your Excel workbook that contains the list of countries.
    2. Press Alt+F11 to open the VBA Editor.
    3. Click on Insert from the menu, then click Module. This will create a new module.
    4. In the new module page, paste the following code:
    Sub PopulateWordDropdown()
    
        Dim WordApp As Object
        Dim WordDoc As Object
        Dim cc As Object
        Dim rng As Range
        Dim cell As Range
    
        Set rng = ThisWorkbook.Sheets("Sheet1").Range("A1:A200") ' Adjust according to your country list range and sheet name
        
        On Error Resume Next
        Set WordApp = GetObject(, "Word.Application")
        If Err.Number <> 0 Then
            Set WordApp = CreateObject("Word.Application")
        End If
        On Error GoTo 0
        
        WordApp.Visible = True
        
        Set WordDoc = WordApp.Documents.Open("C:\path\to\your\word\document.docx") ' Put the path to your Word document here
    
        Set cc = WordDoc.SelectContentControlsByTitle("YourDropdownTitle").Item(1) ' Replace "YourDropdownTitle" with the actual title of your content control
    
        cc.DropdownListEntries.Clear
    
        For Each cell In rng
            If cell.Value <> "" Then
                cc.DropdownListEntries.Add Text:=cell.Value
            End If
        Next cell
    
        WordDoc.Save
        WordDoc.Close
        WordApp.Quit
    
        Set WordDoc = Nothing
        Set WordApp = Nothing
    
    End Sub
    

    Replace "Sheet1" and "A1:A200" with the name of the sheet and the range where your country list is.

    Replace "C:\path\to\your\word\document.docx" with the path to your Word document.

    Replace "YourDropdownTitle" with the actual title of your content control drop-down.

    Press Ctrl+S to save and then close the VBA Editor.

    Run the VBA code by pressing Alt+F8, select PopulateWordDropdown, then click Run.

    Remember to replace the placeholders in the code with your actual values, and as always, be cautious when running VBA scripts due to potential security risks. Also, ensure that macros are enabled in your Excel settings for this code to run.

    This script will open your Word document, clear all existing entries in the drop-down list, populate it with the countries from your Excel list, then save and close the Word document.

    Now next time you open the Word File you will have a Working Drop Down List !


    I hope this helps!

    The answer or portions of it may have been assisted by AI Source: ChatGPT Subscription, it was tested by me and works as it should

    Kindly mark the answer as Accepted and Upvote in case it helped or post your feedback to help !

    Regards

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.