How to create dependent drop-down lists in a Word document?
As the left screenshot shown, you need to limit the choices in the second drop-down list based on the option in the first drop-down, how can you do? This article will show you a method to create dependent drop-down lists in a Word document.
Create dependent drop down lists in Word with VBA code
The below VBA code can help you create a dependent drop-down list in a Word document. Please follow the instructions step by step.
1. Firstly, you need to insert two drop-down lists in your Word document. Click Developer > Legacy Forms > Drop-Down Form Field. See screenshot:
2. Right click the first drop-down list (this drop-down list should be the parent one), and click Properties. See screenshot:
3. In the opening Drop-down Form Field Options dialog box, you need to:
3.1 Enter the category into the Drop-down item box and then click the Add button, repeat the operation until all categories are added to the Items in drop-down list box.
3.2 Enter ddfood into the Bookmark box.
3.3 Click the OK button. See screenshot:
4. Right click the second drop-down list, click Properties to open its Drop-down Form Field Options dialog box, and in the dialog, enter ddCategory into the Bookmark box and click the OK button. See screenshot:
5. Press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
6. In the Microsoft Visual Basic for Applications window, click Insert > Module, then copy below VBA code into the Module window.
VBA code: Create dependent drop-down list in Word
Sub Populateddfood()
'Update by Extendoffice 2018/10/25
Dim xDirection As FormField
Dim xState As FormField
On Error Resume Next
Set xDirection = ActiveDocument.FormFields("ddfood")
Set xState = ActiveDocument.FormFields("ddCategory")
If ((xDirection Is Nothing) Or (xState Is Nothing)) Then Exit Sub
With xState.DropDown.ListEntries
.Clear
Select Case xDirection.Result
Case "Fruit"
.Add "Apple"
.Add "Banana"
.Add "Peach"
.Add "Lychee"
.Add "Watermelon"
Case "Vegetable"
.Add "Cabbage"
.Add "Onion"
Case "Meat"
.Add "Pork"
.Add "Beef"
.Add "Mutton"
End Select
End With
End Sub
Notes:
1) In the code, please change items under each case as you need.
2) ddfood and ddCategory should match the Bookmark options you entered in the above two Drop-down Form Field Options dialog boxes.
7. Save the code and go back to the document.
8. Right click the first drop-down list and click Properties to open the Drop-down Form Field Options dialog box. In the dialog box, please select the above Macro name (here is Popolateddfood) from the Exit drop-down list, and then click the OK button.
9. Now click Developer > Restrict Editing as below screenshot shown.
10. In the Restrict Editing pane , you need to:
10.1) Check the Allow only this type of editing in the document box;
10.2) Select Filling in forms option from the drop-down list;
10.3) Click the Yes, Start Enforcing Protection button;
10.4) In the Start Enforcing Protection dialog, enter the password and click the OK button. See screenshot:
Now a dependent drop-down list is created. When selecting Fruit in the first drop-down list, only the fruit categories can be selected in the second one.
Best Office Productivity Tools
Kutools for Word - Elevate Your Word Experience with Over 100 Remarkable Features!
🤖 Kutools AI Features: Generate Content / Rewrite Text / Document Q&A / Get Quick Answers / Translate documents / Polish Document (Preserve Format)...
📘 Document Mastery: Split Pages / Merge Documents / Export Selection in Various Formats (PDF/TXT/DOC/HTML...) / Batch Convert to PDF...
✏ Contents Editing: Batch Find and Replace across Multiple Files / Resize All Pictures / Transpose Table Rows and Columns / Convert Table to Text...
🧹 Effortless Clean: Sweap away Extra Spaces / Section Breaks / Text Boxes / Hyperlinks / For more removing tools, head to the Remove group...
➕ Creative Inserts: Insert Thousand Separators / Check Boxes / Radio Buttons / QR Code / Barcode / Multiple Pictures / Discover more in the Insert group...
🔍 Precision Selections: Pinpoint Specific Pages / Tables / Shapes / Heading Paragraphs / Enhance navigation with more Select features...
⭐ Star Enhancements: Navigate to Any Location / Auto-Insert Repetitive Text / Toggle Between Document Windows / 11 Conversion Tools...
Best Office Productivity Tools
Kutools for Word - 100+ Tools for Word
- 🤖 Kutools AI Features: Generate, Rewrite, Summarize, Translate Documents / Get Quick Answers / Polish Document (Preserve Format)
- 📘 Document Mastery: Split Pages / Merge Documents / Batch Convert to PDF
- ✏ Contents Editing: Batch Find and Replace / Resize All Pictures
- 🧹 Effortless Clean: Remove Extra Spaces / Remove Section Breaks
- ➕ Creative Inserts: Insert Thousand Separators / Insert Check Boxes / Create QR Codes