Multipe Merges of data

M

Mike Moschella

I am tring to increase the speed of my code that does a
number of merges of datasource data. One way I think I
can get a speed up is to not close the template file in
between the merges. But when I try to Kill
the "C:\DataSource.dat" basic says the file is still in
use. How do I release the file so that I can delete it so
that I can create and attach a new data source file for
the template to use in a merge?


Set mDoc = mWrd.Documents.Open
("C:\TempTemplate.doc")
Set mTempDoc = mWrd.ActiveDocument
Do WHile(more merges to do)
Call CreateDataSource
mDoc.MailMerge.MainDocumentType =
wdFormLetters
mDoc.MailMerge.OpenDataSource
Name:="C:\DataSource.dat"
mWrd.Visible = True
mWrd.Activate
mDoc.MailMerge.Destination =
wdSendToNewDocument
mDoc.MailMerge.Execute
Set mMergeDoc = mWrd.ActiveDocument
mMergeDoc.Activate
mMergeDoc.Saved = True
mMergeDoc.Close
Set mMergeDoc = Nothing
Kill "C:\DataSource.dat"
loop
mDoc.Saved = True
mDoc.Close
Set mDoc = Nothing
Set mTempDoc = Nothing

The Code below works fine I can delete the DataSource File
and createa new one and use it fo the next merge but I
don't want to keep opening and closing the template file
which takes time for each new merge since they all use the
same temeplate file, I want to delete the datasource file
and create a new one and use that.

Do WHile(more merges to do)
Set mDoc = mWrd.Documents.Open
("C:\TempTemplate.doc")
Set mTempDoc = mWrd.ActiveDocument
Call CreateDataSource
mDoc.MailMerge.MainDocumentType =
wdFormLetters
mDoc.MailMerge.OpenDataSource
Name:="C:\DataSource.dat"
mWrd.Visible = True
mWrd.Activate
mDoc.MailMerge.Destination =
wdSendToNewDocument
mDoc.MailMerge.Execute
Set mMergeDoc = mWrd.ActiveDocument
mMergeDoc.Activate
mMergeDoc.Saved = True
mMergeDoc.Close
Set mMergeDoc = Nothing
mDoc.Saved = True
mDoc.Close
Set mDoc = Nothing
Set mTempDoc = Nothing
Kill "C:\DataSource.dat"
loop

Mike
 
P

Peter Jamieson

Try unlinking the mailmerge main document from the datasource before
deleting the data source, e.g. via

mDoc.MailMerge.MainDocumentType = wdNotAMergeDocument
 
G

Guest

Worked great thanks

Mike
-----Original Message-----
Try unlinking the mailmerge main document from the datasource before
deleting the data source, e.g. via

mDoc.MailMerge.MainDocumentType = wdNotAMergeDocument

--
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