Solved

How to preserve formatting in MS Word MailMerge ?

Posted on 2014-12-10
6
1,586 Views
Last Modified: 2014-12-16
I am doing a mailmerge using MS Word 2013. I have a table in an MS Word 2013 file with entries, and a few words have simple formatting (e.g. italics or bold). I want to merge to a new directory (e.g. one or two pages with all the table entries), but when I do this, the formatting is lost, and everything comes out roman (non-italic) characters.
In the mailmerge document, I have tried
MERGEFIELD "Question" \* MERGEFORMAT
and
MERGEFIELD "Question" \* CHARFORMAT
with the same results: no italics or bold.

Is there a way I can create the merge I want?

Thank you.
0
Comment
Question by:Lev Seltzer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 18

Assisted Solution

by:Simon
Simon earned 333 total points
ID: 40491179
Use charformat and while displaying the field codes, format the first character of the field in your desired style.

{MERGEFIELD "Question" \* CHARFORMAT} = print in bold italic when merged.

The best reference I've found on this issue is
www.gmayor.com/formatting_word_fields.htm
0
 

Author Comment

by:Lev Seltzer
ID: 40491260
THank you for your response, but this is not quite what I mean

I have a list in file data.docx. Let's say it looks like this:
FRUIT
Apples
Oranges
Pears

In my really simple merge, I simply want to duplicate this list. I want apples to be BOLD, oranges to be italic and Pears to be neither bold nor italic.

I am not trying to preserve any other aspect of the formatting (e.g. not the font name or size), but I could still manage if all this information copied over.

Does this make sense now?

Thank you.
0
 
LVL 18

Assisted Solution

by:Simon
Simon earned 333 total points
ID: 40491282
I see. If your table includes a separate column with a formatting code in, you could use nested mailmerge {IF} statements to conditionally format the merged version similar to this
{IF FormatCode="BI" "{mergefield Fruit \Charformat}"  {IF FormatCode="B" "{mergefield Fruit \Charformat}" "....} }

But if your table doesn't already contain that format code indicator (B, I, BI...) then  ithink you'd need to add it, or use VBA code to examine each table element and output that "Format Code".

Overall it makes me think that mailmerge isn't the tool for the job.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Lev Seltzer
ID: 40491316
Your suggestion sounds like it could work in different situations, but not mine. My example (above) was really simple, but in fact I have several words in each field, forming a sentence or two, and most words are roman type, and a few words are bold or italic.

You seem to be saying at the end that MS Word MailMerge will ignore the formatting of the source database? I know in my case I can cut and paste the information into a new document, but I was really hoping to use the merge feature, as future merges will be getting more complicated.

THank you.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 167 total points
ID: 40492792
I don't believe that the ability to transfer the formatting was ever in MailMerge. I tried using DDE instead of ODBC, but it had no effect.

What you could do is to run a couple of macros. The first one would be on the datasource document to add markup characters to the bold or italic text.
Sub Markup()
    With ActiveDocument
    'Find in tables can be buggy, so convert to text
        .Bookmarks.Add "bmkTable", .Tables(1).Range
        .Tables(1).ConvertToText vbTab
    End With
    'markup bold words
    With ActiveDocument.Range.Find
        .MatchWildcards = True
        .Text = "(<*>)"
        .Font.Bold = True
        .Replacement.Text = "<b>\1<@@@b>" 'cannot do "<b>\1<\b>": it doesn't like "\b"
        .Execute Replace:=wdReplaceAll
     End With
            
    'markup italic words
    With ActiveDocument.Range.Find
        .MatchWildcards = True
         .Text = "(<*>)"
        .Font.Italic = True
        .Replacement.Text = "<i>\1<@@@i>"
        .Execute Replace:=wdReplaceAll
    End With
     'change "@@@" to "\" as originally intended
    With ActiveDocument.Range.Find
        .MatchWildcards = False
        .Text = "@@@"
        .Replacement.Text = "\"
        .Execute Replace:=wdReplaceAll
    End With
    'recreate the table
    ActiveDocument.Bookmarks("bmkTable").Range.ConvertToTable vbTab
End Sub

Open in new window

The second would run on the result document to convert the markups to formatting:
Sub FormatFont()
    With ActiveDocument.Range.Find
        .MatchWildcards = True
        .Text = "\<b\>([A-z ]{1,})\<\\b\>"
        .Replacement.Font.Bold = True
        .Replacement.Text = "\1"
        .Execute Replace:=wdReplaceAll
    End With
    With ActiveDocument.Range.Find
        .MatchWildcards = True
        .Text = "\<i\>([A-z ]{1,})\<\\i\>"
        .Replacement.Font.Italic = True
        .Replacement.Text = "\1"
        .Execute Replace:=wdReplaceAll
    End With
End Sub

Open in new window

0
 

Author Comment

by:Lev Seltzer
ID: 40493256
GrahamSkan: Thank you for doing more research. I haven't done mailmerge in a while, and instead have been working with MSSQL databases that contain formatted website content and displaying the formatted page content using programming - I remembered incorrectly that I could do this simple task also in mailmerge.

I will try your macros shortly.

Thank you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question