Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the below mail merge code, I

Status
Not open for further replies.

ordendelfai

Technical User
Nov 8, 2002
187
US
Using the below mail merge code, I see that "objWord.Application.Quit" quits the whole word instance altogether.

I have a few situations where I just need to close the document that just merged, not Word altogether. Is there a command to do that?

Thanks,

Joel


-----------------------------Code---------------------------
Public Function MergeIt1EmployeePrint()
Dim objWord As Word.Document
Set objWord = GetObject("C:\MyDB\Templates\ExternalCorrespondence\1EmployeeTermGroup.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Access database.
objWord.MailMerge.OpenDataSource _
Name:="C:\MyDB\Database.mdb", _
LinkToSource:=False, _
Connection:="TABLE tblMailMerge1Employee"
' Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
'The following line must follow the Execute statement because the
'PrintBackground property is available only when a document window is
'active. Without this line of code, the function will end before Word
'can print the merged document.
objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
objWord.Application.ActiveDocument.Saved = True
objWord.Saved = True
If WordWasNotRunning = False Then
objWord.Application.Quit
End If
End Function

-----------------------------Code---------------------------

 
I tried that, but it asks the user to save the document. I researched and found:

ActiveDocument.Close savechanges:=wdDoNotSaveChanges

That did the trick :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top