> The original is no longer the active document. You need to address the
> document you want to close. Something like:
[quoted text clipped - 26 lines]
> > Regards
> > GRaham
Hi Graham,
I think an alternative approach is to set an explicit reference to the mail
merge main document (e.g. when you are opening or creating it or at some
later point)
and then work with it via the object variable E.g. ...
---------------------------------------------------------
Sub Test()
Dim MMMDoc As Document
Set MMMDoc = Documents.Open("c:\temp\TestDoc.doc")
With MMMDoc.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
MMMDoc.Close SaveChanges:=wdDoNotSaveChanges
Set MMMDoc = Nothing
End Sub
---------------------------------------------------------
Regards.
Ed
> Hi
>
[quoted text clipped - 37 lines]
> > > Regards
> > > GRaham
NZ VBA Developer - 16 Jul 2007 22:58 GMT
G'day Graham,
I faced a similar problem with code to email a document as an attachment.
The original code (which I inherited) simply closed the "active" document,
which worked fine unless the user was using Word to edit messages in Outlook.
In that instance, the new mail message became the active document, and the
code closed the message rather than the document that was intended to be used
simply as an attachment and then discarded.
To get around this problem I modified the code to make specific reference to
the attachment document, as follows:
Private Sub cmdEMail_Click()
~OMITTED: code to create variables, hide the userform (to prevent
Outlook/Word from throwing a wobbly about "open dialog boxes") and password
protect the document~
'*** Save the doc in the temp location ***
MyFile = Environ("Temp") & "\MYFILE.doc"
ActiveDocument.SaveAs MyFile
~OMITTED: code to do the Outlook stuff to create the mail message and attach
the temp file~
'*** Close and kill the temp file using a specific reference to the file
rather than just ActiveDocument ***
Documents(MyFile).Close (wdDoNotSaveChanges)
Kill MyFile
~ OMITTED: code to display the mail message and unload the userform~
End Sub
I expect something similar would work for closing your mailmerge template.
Just another take on what Ed said.
Cheers!
> Hi Graham,
>
[quoted text clipped - 71 lines]
> > > > Regards
> > > > GRaham