Problems with mail merge

P

PromisedOyster

We have a C# program that programatically inserts merge fields and into

a Word document. There are basically two different types of merge field

that get inserted:

1. An ordinary merge field
2. An If merge field


Both merge fields insert perfectly well and is getting used in
production extensively.


With the ordinary merge field, the font that gets assigned to the newly

inserted mergefield is the current one (ie the one used for the
surrounding text). However, with the if merge field, the font that
gets applied is the default font, ie Times New Roman. Ideally, this
should behave in exactly the same manner and get the current font.


See code below for example calls:


_wordDoc.MailMerge.Fields.Add(_wordApp.Selection.Range, fieldName);


Word.MailMergeField condition =
_wordDoc.MailMerge.Fields.AddIf(_wordApp.Selection.Range
,fieldName
,wdComparison
,ref oCompareTo
,ref oMissing
,ref oTrueText
,ref oMissing
,ref oFalseText
);


Although I could reselect and apply a font, it seems cumbersome. Is
there an easier way?


Is this a bug or am I doing something wrong?
 
G

Graham Mayor

I don't know C programming, but you need to add a \*charformat switch to
your conditional field to get it to adopt the style of the text into which
it is inserted.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

PromisedOyster

I changed the code as follows but this did not fix the problem

Word.MailMergeField condition =
_wordDoc.MailMerge.Fields.AddIf(_wordApp.Selection.Range
,fieldName + "\\* charformat"
,wdComparison
,ref oCompareTo
,ref oMissing
,ref oTrueText
,ref oMissing
,ref oFalseText
);
 
G

Graham Mayor

The space should really be before the slash not after the asterisk.
" \\*charformat" though I suspect the real problem is that the field is not
being updated.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top