How to Format Five and Nine-Digit ZIP Codes in Word Mail Merge
Question details
The user needs to format ZIP codes dynamically in a Word mail merge so that five-digit codes appear normally and nine-digit codes include a hyphen, without modifying the original Excel data.

- Product
- Microsoft Word / WPS Writer
- Device & OS
- not provided
- Scenario
- Performing a document mail merge using an Excel spreadsheet that contains a mix of five-digit and nine-digit ZIP codes.
- Observed behavior
- Five-digit ZIP codes must display as 12345 and nine-digit codes must display as 12345-6789 automatically upon merging.
Ensure your Excel source data contains the raw numerical ZIP codes in a single column and is successfully linked to your Word document for the mail merge.
Use If...Then...Else Rules in Word Mail Merge
Set up conditional rules in your mail merge document to automatically format ZIP codes based on their numerical value.
This is the most effective Word-only solution. It allows you to dynamically format the ZIP codes during the merge process without altering your original Excel source workbook.
Go to the Mailings tab in Word. Ensure your Excel recipient list is already selected, then click on 'Rules' and select 'If...Then...Else' from the dropdown menu.
Under 'Field name', select your ZIP Code merge field. Change the 'Comparison' to 'Greater than' and type '99999' in the 'Compare to' box.
In the 'Insert this text' box, use Ctrl+F9 to insert the required field braces and type the specific merge field code formatting for nine-digit codes (e.g., adding a hyphen).
For the 'Otherwise insert this text' result, simply insert the standard ZIP Code merge field so that five-digit codes display as standard 12345.

Format the Source Data in Excel (Alternative Method)
If editing Word field codes is too complex, you can apply custom formatting to the ZIP codes directly in Excel before merging.
Seamlessly Format Mail Merge Fields with WPS Writer
WPS Writer offers a comprehensive, highly compatible Mail Merge feature that fully supports Excel data sources and custom field codes. You can effortlessly handle mixed ZIP codes, conditional rules, and formatting tasks in a streamlined interface.
- 1. Launch WPS Writer: Open WPS Office and start a new document or open your existing mailing template.
- 2. Import Excel Data: Navigate to the 'Mailings' tab, click 'Open Data Source', and select your Excel spreadsheet containing the ZIP code records.
- 3. Apply Conditional Rules: Insert your merge fields and use the 'Rules' function to easily set an If...Then...Else condition for >99999 values.
- 4. Preview Merged Data: Click 'View Merged Data' to instantly verify that both your five-digit and nine-digit ZIP codes display with correct hyphenation.

Frequently Asked Questions
Why are leading zeros disappearing from my ZIP codes during the mail merge?
Excel often treats ZIP codes as numbers by default and drops leading zeros (e.g., 01234 becomes 1234). You can fix this by adding a numeric picture switch like \# "00000" to your merge field in Word, or by pre-formatting the column as Text in your Excel spreadsheet.
How do I edit existing mail merge field codes in my document?
You can press Alt+F9 (or Option+F9 on Mac) to reveal the hidden field codes in your document. You can then manually edit the rules, spacing, or formatting switches before pressing Alt+F9 again to hide them and return to standard view.
Is there a way to format ZIP+4 codes directly in Excel without using Word rules?
Yes. In Excel, select the ZIP code column, right-click, and choose 'Format Cells'. Go to the 'Special' category and select 'Zip Code + 4'. Keep in mind that depending on your Word connection method (like DDE vs OLEDB), you may still need to adjust formatting in Word.




