Remove Phone Number Formatting from a Word Mail Merge
Question details
Convert CRM phone numbers to ten digits without punctuation in Word mail merge output.

- 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.
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.
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.
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.
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
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.
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.

Replace the phone pattern with Word wildcards
Use Find and Replace for a one-time cleanup when running a macro is not practical.
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.

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.




