logo
search
Document Editing Problems

Fix Word Mail Merge Field Not Printing Value in Text Box via VBA

Ayan MasoodAyan Masood Oct 1, 2026 868 views

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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the VBA Editor for your current document.

2
Locate the Macro

Find the module or subroutine that handles the insertion of the mail merge data into your text boxes.

3
Extract the Field Result

Modify your variable assignment to read the result of the field. For example: StrBatchNo = ActiveDocument.Fields(1).Result.Text

4
Assign Text to the Shape

Apply the evaluated variable to the text box shape's text range: shpBatchNo.TextFrame.TextRange.Text = StrBatchNo

5
Run the Macro

Save your code and run the macro to populate the text boxes with the actual data values before printing.

Use VBA to Assign the Field's Result Instead of the Code
Update Fields First: Always make sure the mail merge has been executed or the document fields are updated prior to running the macro, ensuring the correct data is fetched.
WPS Office Writer Mail Merge

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. 1. Open Your Document: Launch WPS Writer and open your template document.
  2. 2. Link Data Source: Go to the 'Mailings' or 'References' tab, click 'Open Data Source', and select your spreadsheet.
  3. 3. Insert Fields: Use the 'Insert Merge Field' button to place variables securely into your document layout.
  4. 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.
Fully compatible with Microsoft Word (.docx) formats and mail merge structures.Advanced VBA/Macro support for customizing document layouts and shapes.Intuitive Mail Merge wizard for quick data source linking.Free, lightweight, and fast performance for everyday productivity.
microsoft office alternative - wps office

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.