Fix Word Mail Merge Field Not Printing Value in Text Box via VBA
Question details
The user needs to correctly print the evaluated value of a mail merge field inside a text box via VBA, rather than displaying the field's code.
- Product
- Word
- Device & OS
- not provided
- Scenario
- Populating fixed-position text boxes on a document layout (such as preprinted forms) with mail merge data using VBA scripts.
- Observed behavior
- The mail merge field prints correctly in the main document body, but when inserted into a text box using VBA, it only displays the field name instead of the data value.
Ensure your mail merge data source is correctly connected to the document and that you have basic familiarity with the VBA editor (Alt + F11) in your word processor.
Use VBA to Assign the Field's Result Instead of the Code
Modify your VBA macro to explicitly extract the text result from the evaluated mail merge field and assign it to the text box shape.
When transferring a mail merge field to a shape via VBA, passing the field directly often copies the underlying field code instead of the evaluated data. To resolve this, you must extract the Result.Text property of the field.
Press Alt + F11 on your keyboard to open the VBA Editor for your current document.
Find the module or subroutine that handles the insertion of the mail merge data into your text boxes.
Modify your variable assignment to read the result of the field. For example: StrBatchNo = ActiveDocument.Fields(1).Result.Text
Apply the evaluated variable to the text box shape's text range: shpBatchNo.TextFrame.TextRange.Text = StrBatchNo
Save your code and run the macro to populate the text boxes with the actual data values before printing.

Place the Merge Field in the Document Header
If you are using text boxes merely to place text in fixed locations (like on a preprinted form), using the document header is a more stable alternative that doesn't require VBA.
Effortlessly Manage Mail Merge and Macros in WPS Writer
WPS Writer provides robust Mail Merge tools and full macro/VBA support, making it easy to automate document creation and precisely position fields for preprinted forms.
- 1. Open Your Document: Launch WPS Writer and open your template document.
- 2. Link Data Source: Go to the 'Mailings' or 'References' tab, click 'Open Data Source', and select your spreadsheet.
- 3. Insert Fields: Use the 'Insert Merge Field' button to place variables securely into your document layout.
- 4. Run Macros: Press Alt + F11 to open the WPS Macro Editor, apply your VBA script to move fields into text boxes, and run it seamlessly.

Frequently Asked Questions
Why does my mail merge field show the code instead of the data?
This usually happens when the 'Toggle Field Codes' option is activated. You can press Alt + F9 in your word processor to switch between displaying the raw field codes and the evaluated data results.
Can I insert mail merge fields directly into a text box without VBA?
Yes, you can manually insert a text box, click inside it, and use the 'Insert Merge Field' button from the ribbon. However, if you are automating the process via VBA, you must extract the .Result.Text property to ensure the evaluated value is passed instead of the underlying code.
How do I position mail merge fields for preprinted forms?
The most reliable method is placing the fields in the Header/Footer area or using borderless tables. Text boxes can sometimes shift depending on printer margins or macro executions, whereas headers and tables provide fixed, stable positioning.




