abbaddon223
Registered User.
- Local time
- Today, 09:08
- Joined
- Mar 13, 2010
- Messages
- 162
Hi experts,
I have the below code which is opening a word doc and merging it.
The last two lines of the proceedure are really killing me now
oApp.ActiveDocument.Close
oApp.ActiveDocument.Quit
The first will close the document, but the second errors and says there is no document to quit ?! (Arrrrggghhhh!! :banghead
Can anyone help me please?
Private Sub Command2_Click()
Dim LWordDoc As String
Dim oApp As Object
'Path to the word document
LWordDoc = "D:\Remote Applications\AIA Invoice Management\Merges\8 - 14 Days Chase Letter.docx"
If Dir(LWordDoc) = "" Then
MsgBox "Document not found."
Else
'Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True
'Open the Document
oApp.Documents.Open FileName:=LWordDoc
Set myMerge = ActiveDocument.MailMerge
If myMerge.State = wdMainAndSourceAndHeader Or _
myMerge.State = wdMainAndDataSource Then
With myMerge.DataSource
.FirstRecord = 1
.LastRecord = 100000
End With
End If
With myMerge
.Destination = wdSendToPrinter
.Execute
End With
oApp.ActiveDocument.Close
oApp.ActiveDocument.Quit
End If
End Sub
I have the below code which is opening a word doc and merging it.
The last two lines of the proceedure are really killing me now
oApp.ActiveDocument.Close
oApp.ActiveDocument.Quit
The first will close the document, but the second errors and says there is no document to quit ?! (Arrrrggghhhh!! :banghead

Can anyone help me please?
Private Sub Command2_Click()
Dim LWordDoc As String
Dim oApp As Object
'Path to the word document
LWordDoc = "D:\Remote Applications\AIA Invoice Management\Merges\8 - 14 Days Chase Letter.docx"
If Dir(LWordDoc) = "" Then
MsgBox "Document not found."
Else
'Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True
'Open the Document
oApp.Documents.Open FileName:=LWordDoc
Set myMerge = ActiveDocument.MailMerge
If myMerge.State = wdMainAndSourceAndHeader Or _
myMerge.State = wdMainAndDataSource Then
With myMerge.DataSource
.FirstRecord = 1
.LastRecord = 100000
End With
End If
With myMerge
.Destination = wdSendToPrinter
.Execute
End With
oApp.ActiveDocument.Close
oApp.ActiveDocument.Quit
End If
End Sub