Formatting Issues

Remove Phone Number Formatting from a Word Mail Merge

Huda QurayshiHuda Qurayshi Nov 20, 2026 868 views

Question details

Convert CRM phone numbers to ten digits without punctuation in Word mail merge output.

Remove Phone Number Formatting from a Word Mail Merge
Product
Microsoft Word Mail Merge
Device & OS
not provided
Scenario
A CRM generates documents from a Word template for an ongoing SMS workflow.
Observed behavior
Phone numbers appear as (###) ###-####, but the output needs ten digits with no parentheses, spaces, or hyphens.
Before you start

Confirm that the CRM supplies numbers in the exact pattern (###) ###-#### and check whether the generated document contains other text in that pattern. For a VBA solution, confirm that your organization permits macros and that the template can be saved in a macro-enabled format.

Solution 1Recommended

Run a VBA macro on the merged document

Use this method to replace matching phone numbers after Word or the CRM generates the merged document.

The macro must run on the generated document after the merge, not just on the mail merge template. It searches the document's main text and replaces each matching pattern with its three digit groups.

1
Open the VBA editor

In Word, open the mail merge document or its template and select Developer > Visual Basic. If Developer is hidden, enable it through File > Options > Customize Ribbon.

2
Add the macro

In the VBA editor, select Insert > Module and add: Sub FormatMergedPhoneNumbers() With ActiveDocument.Content.Find .ClearFormatting .Replacement.ClearFormatting .Text = "\(([0-9]{3})\) ([0-9]{3})-([0-9]{4})" .Replacement.Text = "\1\2\3" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute Replace:=wdReplaceAll End With End Sub

3
Save the macro

Select File > Save As and save the main document as a macro-enabled Word document (.docm) or the template as a macro-enabled template (.dotm). Make sure the macro is available to users when they open the generated document.

4
Run it after the merge

Generate the merged document, make it the active document, and select Developer > Macros. Choose FormatMergedPhoneNumbers and select Run. Check that a sample number such as (123) 456-7890 now appears as 1234567890.

Run a VBA macro on the merged document
Automating the workflow: A macro stored in the template does not necessarily run automatically on a newly generated document. A developer can configure an appropriate event or CRM integration to run it after generation; a Document_Open event may require closing and reopening the generated document. The macro also changes any other matching text in the main document body.
Free Microsoft Office alternative

Work with Word documents in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility, making it easy to move everyday document work from Word. The Word VBA automation described above is specific to Microsoft Word and is not replaced by this recommendation.

Review and edit documents containing phone numbers in WPS WriterOpen and save Microsoft Word DOCX documentsUse a familiar interface for everyday document editingMove existing Office documents into a lightweight suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does the macro need to run after the mail merge?

The formatted phone numbers must be present in the generated document before the replacement can find them. Run the macro with that document active, or configure an event or integration that runs after generation.

Can a DOCX file store the VBA macro?

No. Use File > Save As to save the macro-containing document as .docm or the template as .dotm. A generated document can still be processed by a macro made available through a trusted template.

Will the wildcard pattern handle every phone number format?

No. It matches the exact pattern (###) ###-####, including the space after the closing parenthesis. Numbers with a country code, extension, or different punctuation need a different pattern.

Does the macro also change phone numbers in headers and footers?

The example searches ActiveDocument.Content, which covers the main document body. Headers, footers, and other document stories require additional VBA code.