Hello @Ellis, Emma
Welcome to Microsoft QnA!
Although this is a Word Question i have a Solution
Create the list in Excel
- Open your Excel workbook that contains the list of countries.
- Press
Alt+F11
to open the VBA Editor. - Click on
Insert
from the menu, then clickModule
. This will create a new module. - 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