Solved

How to preserve formatting in MS Word MailMerge ?

Posted on 2014-12-10
6
1,184 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
  • 3
  • 2
6 Comments
 
LVL 18

Assisted Solution

by:SimonAdept
SimonAdept earned 333 total points
Comment Utility
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
Comment Utility
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:SimonAdept
SimonAdept earned 333 total points
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Lev Seltzer
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
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…
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now