Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Getting Rid of Spaces in Merged Data.
by Allen Wyatt
(last updated May 14, 2016)
Chris has a mergefield called NHS_Number which brings in a ten-digit number in the format 123 456 7890. He needs to remove the spaces so that the number is displayed as 1234567890. The data comes from a program whose formatting he can't change and the use of VBA isn't acceptable. Chris wonders if there is something he can do with the fields themselves to get rid of the spaces.
One thing you can try is to modify the merge field so that it contains some formatting code. Expand the merge field (put the insertion point within it and press Alt+F9) and then add the following code just before the closing field brace:
Note that there are ten zeros in the formatting code. Once the code is added, and with the insertion point still between the field braces, press Alt+F9 again to collapse the field.
You should note that there are several things that could cause this to not work, the chief culprit being that there is something in your data that causes Word to treat the incoming field as text rather than as a number. If the formatting code doesn't work, your only option is to modify the data that is being merged into your Word document.
Even though you may not be able to change the program that is generating the merge data, there is a good chance that the merge data is in some format that can be changed, such as an intermediate Word document or an Excel workbook. If this is the case, simply open the document or workbook and use the Find and Replace capabilities of either program to search for spaces in the field and remove them.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (8954) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Getting Rid of Spaces in Merged Data.
Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!
An easy way to perform a mail merge starts with creating a data file in a Word document. This tip shows how you can ...Discover More
How Word merges a data source with a document is controlled by merge fields. In those fields you may want to compare ...Discover More
When you are doing a mail merge in Word, you may need to calculate a date sometime in the future. Word doesn't include an ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.