How to find the new document created by a mail-merge?

R

Robin Tucker

Hi,

I am splitting my document into several new documents (by section) and then
performing a mail merge with each section (usually with different data
sets).

How do I find the document object that was created as a result of the mail
merge? I can't find it in the original documents merge object anywhere. I
can't assume it is the last document in the application documents
collection, as the user may be doing other things with another word document
while the merge is proceeding.

Any hints about this?


Thanks


robin
 
D

Doug Robbins

I think that it is unrealistic to think that the user could be doing
something else (with the computer) while the merge is proceeding. However,
I would declare a document object for each of the merges that you are
performing and another one for the main document such as

Dim maindoc as document, result1 as document, result2 at document etc.

Then use

Set maindoc=Documents.Open("path\filename to first mailmerge main document")
With maindoc
'code to attach data source and execute merge
.Close wdDoNotSaveChanges 'close the main document
End with
Set result1 = ActiveDocument

Set maindoc =Documents.Open("path\filename to second mailmerge main
document")
With maindoc
'code to attach data source and execute merge
.Close wdDoNotSaveChanges 'close the main document
End with
Set result2 = ActiveDocument

etc.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
R

Robin Tucker

What you say about it being unrealistic is true in a way, but I'm trying to
eliminate "chance" bugs. My VB.NET application will control the merge via.
automation. It isn't unreasonable to assume the user decides to edit a
document while the merge is taking place. By a 1,000,000 to one chance, he
may open a new document just after my merge code has completed but before
I've had a chance to fetch a reference to the new merge document! In the
end I can just add this as a note in our Twiki database should that
1,000,000:1 event occur - a user advisory so to speak. I was just wondering
if I could easily eliminate it altogether with a few lines of code.

Thanks.
 

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