By Rich Malloy, Tech Help Today, June 2012, updated Nov. 2012
When 93.90 turns into 93.90000000006, there are no less than three ways to put things right.
The Mail-Merge feature of Microsoft Word is one of my favorite parts of the program. It is extremely powerful for creating labels and customized letters, emails, or reports. Once you learn how to use it, you can save countless hours of work. Unfortunately, the task of learning to master all of its idiosyncrasies can give you countless headaches. One of the perennial annoyances of Mail-Merge is its inability to format numbers from an Excel spreadsheet correctly. For example, a sales result in Excel appears as 93.90 but in Word it suddenly becomes 93.900000000000006! Fortunately, there is a way to fix this. In fact, there are three ways. We can modify the spreadsheet, modify the Mail-Merge document, or simply modify the way the two files connect to each other. Although this last approach is little known, for many users it is certainly the best.
Note for users of Office 2007 and Office 2003: The steps presented here are for Office 2010, but the steps needed for older versions of Word and Excel are very similar if not identical.
Rich Malloy is owner / chief consultant at Tech Help Today, a computer-consulting service based in Greenwich, CT. A seasoned veteran of the computer industry, Rich provides high-quality on-site assistance for a vast array of computer problems afflicting residential and small-business clients in Fairfield and Westchester Counties. In his spare time, he teaches as a part-time professor. Contact him at www.techhelptoday.com.
How to Fix Number Formatting in Mail Merge Format Codes for Excels TEXT() Function
Formatting Codes for the Excel TEXT() Function Sample Result 01.10 1.1 1 01 Tue Tuesday 1 01 Jan January 99 1999 1 01
A collection of the most commonly used codes is presented below. A key thing to remember is that 0 signifies a digit that will always appear even if zero , while # specifies a digit that will appear only if it is not a leading or trailing zero. Thus, the code 00000 will ensure that the leading zero is not truncated from New Jersey postal zip codes. These codes for numbers, dates, and times can be used in the TEXT function or in Excels Custom number formats. As an extra bonus, they can also be used in the Numeric Switches in Word Mail-Merge Fields described in the next section. Unfortunately, there is a slight difference between the way these codes work in Excel and Word in Microsoft Office 2010. In Excel, you can use either M or m for months or minutes. In almost all cases, Excel is smart enough to figure out which units you are talking about. But Word is not so smart, and you must use the capitalized letter to refer to months. Also, Excel has an additional code, MMMMM, which returns a single letter abbreviation for the month (e.g., J, F, M, A, ).
Code 00.00 #,##0.## D or d DD or dd DDD or ddd DDDD or dddd M MM MMM MMMM YY or yy YYYY or yyyy H or h HH or hh
M 1 Supplementing a spreadsheet table with a few TEXT() Mm 01 functions is a simple and direct approach. If you are using more than one or two these functions, however, your S or s 1 spreadsheet soon becomes cluttered with seemingly redundant SS or ss 01 columns. Analyzing the spreadsheet becomes impossible, and H 23 there is great likelihood that you will mistakenly use a h am/pm 11 PM TEXT() function as input for a calculation, thereby yielding nonsense results. Our advice here is to put all your TEXT() functions on another worksheet, entitled something like Data for Mail Merge.
Instead of the TEXT() function, some users prefer to use the ROUND() function to trim off extra decimal places. As its name implies, Excels ROUND() function will permanently round a number up or down to the number of decimal places you specify. The advantage is that the rounded number is not text and can still be used for further calculations. In many cases, the ROUND() function will work well with Mail Merge, but you may want to steer clear of it because of the following reasons: 1. The Round() function will not preserve the dollar sign or the thousands separator (comma) 2. The Round() function will truncate trailing zeros 3. The Round() function sometimes causes MailMerge to display the wrong number of decimal places. For example, a MailMerge document occasionally shows 4 decimal places when the Round() function had specified 2 or 3.
Page 2 of 5
4. In rare cases, the Round() function causes MailMerge showed a slightly different number. For example, instead of displaying 1.0014, MailMerge showed 1.0013.
As you can see, the numeric switch codes are identical to the Excel formatting codes except that they are preceded by \# for numbers and \@ for dates. To see more of the codes available, refer to the table above, or see the online help for numeric switch in Word 2010. Here are some examples of how the numeric field codes work with data in a column labeled Sales in an Excel spreadsheet.
Numeric Switches for Mail-Merge MergeFields Word Result
$12,345.23 $-12,345.23 $12,345.23 0,006 5.67 5. 5.00 0.67 .67 12 345.23
Excel Data
12345.2345 -12345.2345 12345.2345 5.67 5.67 5 5 0.67 0.67 12345.2345
Field Code { MERGEFIELD { MERGEFIELD { MERGEFIELD { MERGEFIELD { MERGEFIELD { MERGEFIELD { MERGEFIELD { MERGEFIELD { MERGEFIELD { MERGEFIELD Sales \# $#,##0.00 } Sales \# $#,##0.00 } Sales \# $,#,##0.00 } Sales \# 0,000 } Sales \# 0.## } Sales \# 0.## } Sales \# 0.00 } Sales \# 0.## } Sales \# #.## } Sales \# # ##0.00 }
Page 3 of 5
In light of the fact that Word and Excel use the same formatting codes, we could not help wondering why they dont use the same function format. For example, why not have the MergeField function look something like: { MERGEFIELD(Donation,"$#,##0.00") } Good question. Youll have to ask Microsoft. Note: Before you start cursing me out, try to remember that when you add or change a numeric switch, the effect is not shown immediately. You either have to update the field (right-click it and choose Update Field), or click the button Mailings > Preview Results 2 or 3 times, or if you are using the Mail-Merge Wizard, you will have to go back a step and return to see the effect of your changes. (I am not making this up. Remember, only geniuses work at Microsoft. We are just not smart enough to appreciate their brilliance.) The numeric switches in merge fields work well, but I find the process very difficult to remember. (Is it a forward slash or a back slash?) Also, it is very easy to make a mistake. Fortunately, there is another way.
Thats all for the first step, and you never have to do it again. From now on, your copy of Word can open up many different types of files, and can open these by different avenues, including DDE. The only side effect of the above is that every time you open a non-Word file with Word, the program will give you a chance to change your mind. No problem. The second and last step has to be done each time you select a data source for your Mail-Merge operation (either in Step 3 of Words Mail-Merge Wizard or after you press the Select Recipients button in the Mailings ribbon). Relax. It is just three additional mouse clicks: After you have chosen the data file you would like to use, a new Confirm Data Source dialog box will appear.
After you choose a data file, the Confirm Data Source dialog box will appear.
Page 4 of 5
The default type of link is by OLE, but that is not what you want. In the Confirm Data Source dialog box, click the check box to Show all. In the expanded list of file types, choose MS Excel Worksheets via DDE (*.xls). (Choose this even if you are using the newer Excel file format: *.xlsx.) If asked, confirm that you are selecting the Entire Spreadsheet.
If you have already selected a spreadsheet for your Word document, you may have to select it again, this time via a DDE link. Thats it! From now on, your Excel formatting will travel over to Word Mail-Merge documents fairly intact. One huge caveat here: Make sure that the data you want to merge are in the first sheet of your Excel workbook. (It took us two hours to finally figure out that DDE does not see anything but the first Excel worksheet.)
To see an option for DDE linking, you have to click the check box for Show all.
Sounds good. So, you ask, if this is so good, why didnt the geniuses at Microsoft simply do this by default? Another good question. In previous versions of Word, there were a few minor downsides to this approach. But in my tests with Word 2010, these problems seem to have been fixed. But for how long? It is perhaps significant that the DDE link option refers only to the old *.xls file format rather than the new one used by Excel 2007 and 2010. Can Microsoft be trying to sunset this option? Lets hope not. [Some of the ideas expressed above are from C. Dudas on the Web.]
Page 5 of 5