VBA & Macro Problems

Use IF Logic and Conditional Formatting in Microsoft Word Forms

Khadija KhanKhadija Khan Nov 14, 2026 869 views

Question details

Configure a restricted-editing Word form so dropdown choices control other fields, paragraph visibility, and list formatting.

Product
Microsoft Word for Microsoft 365
Device & OS
not provided
Scenario
A form author wants dropdown selections to determine which content and formatting users see.
Observed behavior
Dropdown choices should trigger conditional updates to other form controls, paragraphs, and lists.
Before you start

Open the form in desktop Word and enable the Developer tab through File > Options > Customize Ribbon if it is hidden. Identify the dropdown choices and content that each choice should affect, and check whether you can remove the form's editing restriction while configuring it.

Solution 1Recommended

Use content controls and VBA to respond to dropdown selections

Use a content control exit event to apply conditional changes when a user leaves a dropdown.

Word does not provide Excel-style conditional formatting for form fields. A VBA event can inspect a dropdown value and update other content controls or formatting.

The example below hides or shows a tagged content control in a form protected without a password. It does not update other dropdowns or list formatting; add separate conditions and actions for those requirements.

1
Create the dropdown

On the Developer tab, insert a Drop-Down List Content Control. Open Developer > Properties, set its Tag to Visibility, and add the choices Show and Hide.

2
Tag the conditional content

Select the paragraph or text to control and insert a Rich Text Content Control from Developer. Open its Properties and set its Tag to ConditionalText.

3
Add the exit event

Press Alt+F11, open ThisDocument for the form in the VBA editor, and paste this code: Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim target As ContentControl Dim protection As WdProtectionType Dim hideContent As Boolean If ContentControl.Tag <> "Visibility" Then Exit Sub Select Case Trim$(ContentControl.Range.Text) Case "Show": hideContent = False Case "Hide": hideContent = True Case Else: Exit Sub End Select protection = Me.ProtectionType On Error GoTo Failed If protection <> wdNoProtection Then Me.Unprotect For Each target In Me.SelectContentControlsByTag("ConditionalText") target.Range.Font.Hidden = hideContent Next target If protection <> wdNoProtection Then Me.Protect Type:=protection, NoReset:=True Exit Sub Failed: On Error Resume Next If protection <> wdNoProtection And Me.ProtectionType = wdNoProtection Then Me.Protect Type:=protection, NoReset:=True End If On Error GoTo 0 MsgBox "The form could not be updated. Check its protection and control tags." End Sub

4
Save and test the form

Save the document as a Word Macro-Enabled Document (.docm). In Developer > Restrict Editing, apply the desired restriction without a password for this example. Enable macros if prompted, choose Show or Hide, and move focus out of the dropdown to run the event.

5
Extend the conditions

Return to ThisDocument in the VBA editor and add Select Case branches for your actual choices. Use the tagged controls' ranges to update other fields or apply the required list formatting, then test every choice under the intended restriction.

Use content controls and VBA to respond to dropdown selections
Hidden text is not secure: Hidden text can still appear if Word is set to display hidden formatting marks or print hidden text. Password-protected forms require additional protection handling; do not hard-code a sensitive password in the macro.
Free Microsoft Office alternative

Edit Word Documents with WPS Office

WPS Office is a free, lightweight Office alternative with a familiar interface for opening and editing documents. Its Microsoft Word format compatibility makes it easier to move existing files, though it does not fix Word's VBA or restricted-editing behavior.

Open and edit Microsoft Word DOC and DOCX filesWork with document text, paragraphs, bullets, and numberingUse a familiar interface for everyday document editingChoose a free, lightweight alternative for routine Office work
microsoft office alternative - wps office

Frequently Asked Questions

Can a Word dropdown automatically hide a paragraph without VBA?

A standard content control does not provide an Excel-style conditional formatting rule. For automatic changes in a form, use a VBA event or another form-building approach.

When does the content control exit event run?

Document_ContentControlOnExit runs when the user leaves a content control. Put the event procedure in the document's ThisDocument module and test by moving focus out of the dropdown.

Why does the form not respond to my dropdown selection?

Check that the file is saved as .docm, macros are enabled, the procedure is in ThisDocument, and the control tags and dropdown values match the code. Editing protection can also prevent changes unless the code handles it.

Can VBA change bullets or numbering based on a selection?

Yes. In the dropdown's event procedure, use If or Select Case to select the appropriate action, then apply list formatting to the relevant paragraph range. Test the result with the form's editing restriction enabled.

Does hiding text prevent users from seeing it?

No. Hidden text is a formatting setting, not a security measure. Users may display it through Word's formatting-mark settings, and it may print if hidden-text printing is enabled.