A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Multipe Merges of data



 
 
Thread Tools Display Modes
  #1  
Old June 14th, 2004, 09:59 PM
Mike Moschella
external usenet poster
 
Posts: n/a
Default Multipe Merges of data

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
  #2  
Old June 15th, 2004, 08:17 AM
Peter Jamieson
external usenet poster
 
Posts: n/a
Default Multipe Merges of data

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

mDoc.MailMerge.MainDocumentType = wdNotAMergeDocument

--
Peter Jamieson

"Mike Moschella" wrote in message
...
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



  #3  
Old June 16th, 2004, 09:35 PM
external usenet poster
 
Posts: n/a
Default Multipe Merges of data

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

"Mike Moschella"

wrote in message
...
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



.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:20 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.