Skip to main content
 

How to create dependent drop-down lists in a Word document?

Author: Siluvia Last Modified: 2024-08-01
Example showing limiting the choices in the second drop-down list based on the selected option in the first drop-down list


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


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:

Developer tab with Legacy Forms selected and Drop-Down Form Field highlighted

2. Right click the first drop-down list (this drop-down list should be the parent one), and click Properties. See screenshot:

First drop-down list right-clicked with Properties option selected

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:

Drop-down Form Field Options dialog box

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:

Drop-down Form Field Options dialog box

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.

Drop-down Form Field Options dialog box

9. Now click Developer > Restrict Editing as below screenshot shown.

Restrict Editing button on the Developer tab on the ribbon

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:

Restrict Editing pane and Start Enforcing Protection dialog

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.

Examples showing limiting the choices in the second drop-down list based on the selected option in the first drop-down list

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...

Kutools and Kutools Plus tabs on the Word Ribbon
👉 Want to try these features? Download Kutools for Word now! 🚀
 

Best Office Productivity Tools

Kutools for Word - 100+ Tools for Word