logo
search
Office Settings & Configuration

How to Use a Word Dropdown to Show Text Boxes with VBA

Maira MehtabMaira Mehtab Sep 27, 2026 870 views

Question details

The user wants to create a Word dropdown menu with different options, such as languages, and use a VBA macro to dynamically populate a text box or conditionally display a second text box based on the selected dropdown value.

Product
Word
Device & OS
not provided
Scenario
Creating dynamic forms or automated document templates where certain text fields update, appear, or disappear depending on the user's choices in a dropdown list.
Observed behavior
Word does not immediately trigger an event or update the document the moment a dropdown option is clicked; the VBA code requires a specific trigger to recognize the selection and execute the changes.
Before you start

Ensure the Developer tab is enabled in your Word ribbon to access Content Controls and the Visual Basic editor, and remember to save your file as a Macro-Enabled Document (.docm) to prevent losing your VBA code.

Solution 1Recommended

Use the ContentControlOnExit Event in VBA

Because Word dropdowns do not trigger an immediate action upon clicking, use the OnExit event to execute your code when the user presses Tab or clicks outside the dropdown field.

Content Controls in Word do not have an 'OnClick' or 'OnChange' event that fires immediately when an item is selected from a dropdown. Instead, you must use the Document_ContentControlOnExit event.

This event executes the assigned VBA script as soon as the user leaves the dropdown field, allowing you to read the selected value and manipulate the text boxes accordingly.

1
Insert Content Controls

Navigate to the Developer tab. Insert a Drop-Down List Content Control for your language options, and add Rich Text Content Controls or Shape Text Boxes for the dynamic fields.

2
Assign Tags to Controls

Select each control, click 'Properties' in the Developer tab, and assign a unique Title and Tag (e.g., 'LanguageDropdown', 'TextBox1') so your VBA script can accurately target them.

3
Open the VBA Editor

Press ALT + F11 to open the Visual Basic for Applications editor. In the Project Explorer pane on the left, double-click 'ThisDocument' under your current document's project to open the code module.

4
Add the OnExit Macro

Write a Private Sub Document_ContentControlOnExit macro. Within this sub, use If...Then or Select Case statements to check the value of your 'LanguageDropdown' tag, and then write commands to populate the first text box and adjust the .Visible property of the second text box.

5
Trigger the Macro in the Document

Close the VBA editor and return to your document. Select a value from the dropdown list, then press the 'Tab' key or click anywhere else in the document to trigger the exit event and update the text boxes.

Troubleshooting macro execution: If the text boxes do not update after pressing Tab, verify that macros are enabled in your Trust Center settings. If the document behaves erratically, restarting or reinstalling the Word application has been reported to resolve underlying bugs preventing the event from firing.
Automate Documents with WPS Writer

Create Dynamic Dropdowns and Forms in WPS Office

WPS Writer offers excellent support for form fields, content controls, and macros. You can easily build dynamic templates, automate text box filling, and manage dropdown selections within a highly compatible and familiar interface.

  1. 1. Enable the Developer Tools: Open WPS Writer, go to your settings or customize the ribbon to ensure the Developer tab is visible.
  2. 2. Insert Dropdowns and Text Boxes: Use the Form Controls located in the Developer tab to insert drop-down menus and text fields into your document layout.
  3. 3. Add VBA Macros: Click the 'Macros' or 'Visual Basic' button to open the integrated VBA editor and paste your automation scripts for seamless document formatting.
Fully compatible with Microsoft Word VBA scripts and macro-enabled documents (.docm)Intuitive Developer tab for quick insertion of form controls and dropdownsLightweight application that loads fast and processes macros efficientlyFamiliar UI that requires zero learning curve for advanced document editing
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my text box updating immediately after selecting a dropdown option?

Word dropdown content controls lack an automatic 'OnChange' trigger. Changes are processed using the 'ContentControlOnExit' event. This requires you to click away from the dropdown or press the Tab key to trigger the code that updates the text box.

How do I hide a specific text box using VBA in Word?

To hide a text box, you must reference it as a Shape object in your VBA code and set its `.Visible` property to `msoFalse`. Ensure the text box is inserted as a floating shape rather than inline text for the visibility toggle to work properly.

Can I populate a text box with different text based on the dropdown selection?

Yes. Inside the Document_ContentControlOnExit event, use a Select Case statement to evaluate the selected text of the dropdown control. Depending on the matched value, you can assign different string values to the text box's range.

What file format do I need to save my document in for VBA to work?

To preserve and execute your VBA code, you must save your file as a Word Macro-Enabled Document (.docm). Saving it as a standard .docx will remove the VBA script and disable the automation.