How to Close original Document after executing MailMerge.

D

Don

Hello, I'm doing a MailMerge from within an access application using code.
How do close the original document after running the execute statement that
opens my second word document. I want to close the original
document(MasterTest.doc) with no prompts to user but keep the new document
open.

Dim objApp As Object
Dim strDocName As String
strDocName = rs!ClosingDir & "\MasterTest.doc"
Set objApp = CreateObject("Word.application")
With objApp
.Visible = True
.Documents.Open strDocName
.activedocument.mailmerge.Destination = 0 'wdSendToNewDocument
.activedocument.mailmerge.Execute
'***Somehow close original document
'.Close 0 'wdDoNotSaveChanges
' .ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
End With
 
D

Doug Robbins - Word MVP

Dim objApp As Object
Dim strDocName As String
strDocName = rs!ClosingDir & "\MasterTest.doc"
Set objApp = CreateObject("Word.application")
With objApp
.Visible = True
Dim MainDoc as Document
Set MainDoc = .Documents.Open strDocName
With MainDoc
.mailmerge.Destination = 0 'wdSendToNewDocument
.mailmerge.Execute
.Close wdDoNotSaveChanges
End With
End With
--
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top