Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Dixie Dixie is offline
external usenet poster
 
Posts: 22
Default Closing a template from the autoOpen macro

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


  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Closing a template from the autoOpen macro

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


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

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



  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Closing a template from the autoOpen macro

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


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



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Understanding Macros MrsMac Microsoft Word Help 21 April 7th 06 03:15 PM
How to I lock a template for modification only? PegSCK Microsoft Word Help 4 February 24th 06 09:45 PM
How Come? Michael Koerner Mailmerge 9 February 10th 06 10:29 PM
Global/Master Template [email protected] New Users 1 October 27th 05 03:34 PM
Templates gman Page Layout 17 April 22nd 05 06:35 PM


All times are GMT +1. The time now is 12:04 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"