How to Show or Hide a Word Text Box Based on a Mail Merge Field
Question details
The user needs to conditionally display a section and a text box during a Word mail merge based on specific values from an Excel data source.
- Product
- Word
- Device & OS
- not provided
- Scenario
- Setting up a mail merge document where specific sections or text boxes should only print or appear if certain data conditions in the linked Excel spreadsheet are met.
- Observed behavior
- By default, text boxes appear on all merged documents. The goal is to make the text box dynamically display or hide based on the evaluation of an IF field.
Ensure your Excel data source is properly linked to your document and that you have identified the exact merge field name that will act as the condition trigger.
Use an IF Field to Conditionally Display the Text Box
Insert an IF field statement to evaluate your mail merge data, placing the text box inside the true condition's quotation marks.
Word's field codes allow for dynamic document generation. By nesting a text box inside an IF field, you can dictate exactly when that text box renders based on the data pulled from Excel.
Press Alt + F9 on your keyboard to reveal the underlying field codes in your document.
Press Ctrl + F9 to insert empty field brackets. Inside the brackets, type your condition, such as: IF { MERGEFIELD YourConditionField } = "Yes" "" "".
Cut the text box you want to display. Place your cursor inside the first set of empty quotation marks (the 'true' result) and paste the text box. Ensure the text box's anchor paragraph is also within these quotes.
Press Alt + F9 again to hide the codes, then preview your mail merge to verify the text box appears only when the condition is met.

Use a Frame Instead of a Text Box
Switch from a floating text box to a frame, which integrates better with inline styles and conditional field codes.
Master Mail Merge and Conditional Fields with WPS Office
WPS Writer provides intuitive and powerful mail merge capabilities. You can seamlessly link Excel data sources, insert conditional field rules, and format dynamic document layouts effortlessly.
- 1. Open WPS Writer: Launch WPS Writer and navigate to the 'Mailings' tab on the top ribbon.
- 2. Connect Data Source: Click 'Open Data Source' to select and link your Excel spreadsheet.
- 3. Insert Conditional Rules: Click on 'Word Fields' and select 'If...Then...Else...' to set up your conditional logic.
- 4. Format and Preview: Paste your text box into the appropriate conditional result area and click 'View Merged Data' to test your dynamic layout.

Frequently Asked Questions
Why does my text box appear on every page regardless of the mail merge condition?
This happens if the text box's anchor paragraph is left outside the IF field's quotation marks. Ensure you select both the text box and its underlying paragraph marker before dragging or pasting it into the 'true' result quotes.
What is the keyboard shortcut to view field codes?
You can toggle field codes on and off by pressing Alt + F9 on Windows. If you only want to reveal a specific field code, select it and press Shift + F9.
Can I use multiple conditions to show a text box?
Yes. You can nest multiple IF fields inside one another or use an advanced combination of logical fields (like AND/OR) depending on your needs, but nesting is generally the most reliable method for complex conditional layouts.
Why is a frame recommended over a text box for mail merge?
Frames are an older formatting tool that acts inline with the text. Because they aren't floating objects, word processors process them more predictably within complex field calculations and style definitions.




