Suppress error messages when merging in batch

K

karen_greenwood

We do merge in Word through a batch job. This is fine unless there is
an error, for example one of the records in the data file is
incomplete. Then the merge hangs. If such a merge were run online
the user would see the error message and acknowledge it, but in batch
mode there is no way to acknowledge it. Is there any way to avoid the
hanging and instead have Word exit and return an error code to the
calling program?
 
P

Peter Jamieson

As far as I know because I don't do bulk stuff like this,
a. you cannot trap all errors using the Word object model. For example, you
cannot trap the "error" where the Mail Merge Data Source does not exist.
b. You probably already know that you can reduce the possible number of
dialog messages by setting

objWordApplication.DisplayAlerts = wdAlertsNone

(where objWordApplication is your Word Applicaiton object

c. You can suppress some types of error by executing the merge using

objWordApplication.objMMMD.MailMerge.Execute Pause:=False

(rather than objWordApplication.objMMMD.MailMerge.Execute Pause:=True)

where objMMMD is your Mail Merge Main Document object

If you do that, some syntax errors will be logged in a separate Errors
document. But how do you know that such a document has been created? Well,
you can compare the document count and document names pre- and post- merge.
For example, if pre-merge your document count is always 1, then
1. if you are merging to a new document and there are no errors, post-merge
you should see 2 documents (MMMD, destination document), and the
ActiveDocument should be the Destination Document
2. if you are merging to a new document and there are errors, post-merge
you should see 3 documents (MMMD, destination document, error document), the
ActiveDocument should be the error document, and the ActiveDocument.Name
should be something like "Mail Merge ErrorsNNN" where NNN is a sequence
number (at least, in Word 2003, English Language version it's like that).
3. if you are merging to any other destination type and there are no
errors, post-merge you should see 1 document (MMMD), and the ActiveDocument
should be the MMMD
4. if you are merging to a any other destination type and there are errors,
post-merge you should see 2 documents (MMMD, error document), the
ActiveDocument should be the error document, and the ActiveDocument.Name
should be as above.

I know that some simple errors, e.g. you have a formula field { ={
MERGEFIELD myfield } } and myfield is not numeric) will be dealt with by
setting .DisplayAlerts = wdAlertsNone anyway (in other words, if those are
the only types of error you get, you don't need to contemplate produing an
Error Document, but if you do, an Error Document will be produced when this
error occurs, regardless of the state of .DisplayAlerts). However, I don't
have enough experience of doing that to tell you exactly what types of error
are trapped by what technique.

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