ordendelfai
Technical User
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 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---------------------------