Solved

How to preserve formatting in MS Word MailMerge ?

Posted on 2014-12-10
6
1,739 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
Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

 

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
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…

717 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