Help needed to automate Mail-Merge

R

roudoudouze

My program uses COM to automate a mail-merge process.
When the mail-merge is complete, the Documents collection of the
Application
contains three or four documents : the template, the datasource, the
mail-merge
output and, if applicable, the mail-merge error report.
Is there a way to differentiate these documents, i.e. how to identify
which one
is the mail-merge output ?
At the moment, I'm using the document name, but this does not work when
running
my program with non-english MS-Office
 
P

Peter Jamieson

I don't have code for this, but I think what you need to do to cope with all
possible outcomes is
a. iterate through the Documents collection before the merge and save the
document names. Let's suppose there are n names
b. set a reference to the Mail Merge Main Document before you merge
c. after the merge, there will be n documents, n+1 documents or n+2
documents.
d. the reference you set will still be to the Mail Merge Main Document
e. If you have n+1 documents and you were merging to a new document, there
is no Error Document and the ActiveDocument post-merge will be the output
document
f. if you have n+1 documents post-merge and you were not merging to a new
document (/and/ you used the Pause:=False parameter in the MailMerge.Execute
method, then the ActiveDocument post-merge will be the error document
g. if you have n+2 documents post-merge then the ActveDocument will be the
Error document, and (as far as I know) nothing references the output
document. It may be that you can rely on looking at the [n+1]th or [n+2]
member of the Documents collection to get a reference to the Output
Document, but I would personally tend to iterate through the Documents
collection looking for the document with a name that was not one of the n
names pre-merge, and where the name is not the same as the name of
ActiveDocument (i.e. the error document).

I will probably do some code for this soon but don't hold your breath.

Peter Jamieson
 

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