?
Solved

How to preserve formatting in MS Word MailMerge ?

Posted on 2014-12-10
6
Medium Priority
?
1,960 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 1332 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 1332 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: 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.

 

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 668 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 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