ChrisCalvert
Technical User
I use the code below which I coppied from ..Technet, I think.
However, this opens a second copy of my database, and leaves the Merge document, and the new merged document open.
I would like to keep the second copy of my database from opening, and close the word documents, without saving anything.
I tried using 'objWord.Application.Quit' but that still asks for saving changes, so I am not sure if that is what I want.
Can anyone help me? Thanks in advance....
------------------------
Public Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("C:\FufilDataMerge\StopPayLetter.doc", "Word.Document"
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source
objWord.mailmerge.OpenDataSource _
Name:="C:\FufilDataMerge\Fulfilment.mdb", _
LinkToSource:=True, _
Connection:="TABLE StopLettersData", _
SQLStatement:="SELECT * FROM [StopLettersData]"
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
End Function
However, this opens a second copy of my database, and leaves the Merge document, and the new merged document open.
I would like to keep the second copy of my database from opening, and close the word documents, without saving anything.
I tried using 'objWord.Application.Quit' but that still asks for saving changes, so I am not sure if that is what I want.
Can anyone help me? Thanks in advance....
------------------------
Public Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("C:\FufilDataMerge\StopPayLetter.doc", "Word.Document"
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source
objWord.mailmerge.OpenDataSource _
Name:="C:\FufilDataMerge\Fulfilment.mdb", _
LinkToSource:=True, _
Connection:="TABLE StopLettersData", _
SQLStatement:="SELECT * FROM [StopLettersData]"
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
End Function