Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / August 2006

Tip: Looking for answers? Try searching our database.

Closing a template from the autoOpen macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dixie - 24 Aug 2006 01:22 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.