I have a mailmerge template with the following AutoOpen macro
ActiveDocument.MailMerge.OpenDataSource "C:\MergeData\LevelData.txt"
ActiveDocument.MailMerge.Execute
I want this template to automatically close when the mailmerge is executed
to the new document because I don't want to have to manually close two Word
documents after the mailmerge has happened.
Is there another line of code that can achieve that?
dixie
Doug Robbins - Word MVP - 24 Aug 2006 04:35 GMT
Dim maindoc as Document
Set maindoc = ActiveDocument
With maindoc
.MailMerge.OpenDataSource "C:\MergeData\LevelData.txt"
.MailMerge.Execute 'you may want to specify the destination
.Close wdDoNotSaveChanges
EndWith

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
>I have a mailmerge template with the following AutoOpen macro
>
[quoted text clipped - 8 lines]
>
> dixie
Peter Jamieson - 24 Aug 2006 09:40 GMT
When you merge to a new document, it becomes the Activedocument. So you need
something more like
Dim objMainDocument As Word.Document
Set objMainDocument = ActiveDocument
objMainDocument.MailMerge.OpenDataSource "C:\MergeData\LevelData.txt"
objMainDocument.MailMerge.Execute
' if you want to save and close the new document, use something like
ActiveDocument.Saveas Filename:="whatever.doc"
ActiveDocument.Close Savechanges:=False
' To close the main document...
objMainDocument.Close
Peter Jamieson
>I have a mailmerge template with the following AutoOpen macro
>
[quoted text clipped - 8 lines]
>
> dixie