Share via

Mail Merge Coding & Number Formatting

Anonymous
2016-02-09T20:39:41+00:00

I'm creating an industry directory using Excel to Word Mail Merge. I'm struggling with formatting the phone numbers into ###-###-#### or (###) ###-#### structure without it overriding my b: command. I tried using the DDE command process so the formatting would come through Excel to Word but Office support wasn't able to figure out why it wouldn't work after an hour and a half on the phone.

Also, the company names and addresses are duplicating with each entry and I'd like to find the code that will eliminate that problem. I found a few codes online that are similar but I couldn't get any to work. Any help would be appreciated!

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Paul Edstein 82,861 Reputation points Volunteer Moderator
2016-02-10T04:26:18+00:00

The data duplications are likely to be the result of inserting the mergefields multiple times.

The mergefield \b & \f switches don't work with other switches. Presumably you have conditional content to go with the # (e.g. 'Phone:'). In that case you could use a field coded along the lines of:

{IF{MERGEFIELD Phone}<> "" "Phone: {MERGEFIELD Phone # "'('###') '###'-'####"}"}

Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field construction are all required.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323K Reputation points MVP Volunteer Moderator
2016-02-10T00:08:59+00:00

See "Formatting Word fields with switches" on fellow MVP Graham Mayor's website at

http://www.gmayor.com/formatting\_word\_fields.htm

If the formatting switches are messing with the \b switch (I assume that is what you mean by b: command), you can achieve the same result by using an If...then...Else field construction.

To sort out the issue with the duplications, it would be necessary to see the files.  If you want to send me a copy of the mail merge main document and of the data source, I will investigate the issue.

Was this answer helpful?

0 comments No comments

13 additional answers

Sort by: Most helpful
  1. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2016-02-10T21:01:28+00:00

    Now my only problem is having a blank space if there is no data in a cell. So if they didn't enter a fax there is just empty space.

    ie

    Phone: (###) ###-####

    Cell: (###) ###-####

    Email:

    And last I just need to figure out how to stop the company from repeating...

    Suppressing the empty lines requires nothing more than incorporating the line/paragraph breaks into the IF field:

    {IF{MERGEFIELD Phone}<> "" "Phone: {MERGEFIELD Phone # "'('###') '###'-'####"}

    ¶"}{IF{MERGEFIELD Fax}<> "" "Fax: {MERGEFIELD Fax # "'('###') '###'-'####"}

    ¶"}{IF{MERGEFIELD Cell}<> "" "Cell: {MERGEFIELD Cell # "'('###') '###'-'####"}

    ¶"}Email: {MERGEFIELD Email}

    where ¶ is the line/paragraph break.

    For more mailmerge formatting tips, see my Mailmerge Tips and Tricks thread at:

    http://www.msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html

    or:

    http://windowssecrets.com/forums/showthread.php/163017-Word-Mailmerge-Tips-amp-Tricks

    As for the company, I repeat what I said earlier:

    The data duplications are likely to be the result of inserting the mergefields multiple times.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-02-10T16:09:19+00:00

    That link is awesome! Wish I'd found it months ago.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-02-10T15:53:55+00:00

    IT'S WORKING!!!!!

    Now my only problem is having a blank space if there is no data in a cell. So if they didn't enter a fax there is just empty space.

    ie

    Phone: (###) ###-####

    Cell: (###) ###-####

    Email:

    And last I just need to figure out how to stop the company from repeating...

    Was this answer helpful?

    0 comments No comments