S
scott
My below sub opens a word mail merge document, executes the merge to a new
merged word document and then closes the original word mail merge doc. It
works fine except the new word doc ends up minimized and my access instance
is the active window.
How can I force the active window to be the new merged word document? I
tried using objWord.Activate but it doesn't set the new merged word document
to the active window.
CODE ****************************
Public Sub WordMergeTest()
On Error GoTo WordMergeTest_Err
Dim objWord As Word.Application, objDocument As Object, ActiveDocument
As String
Set objWord = New Word.Application
ActiveDocument = "c:\data\\Company\myMailMerge.doc"
objWord.Visible = True
objWord.Documents.Open ActiveDocument
objWord.ActiveDocument.MailMerge.Destination = wdSendToNewDocument
objWord.ActiveDocument.MailMerge.SuppressBlankLines = True
objWord.ActiveDocument.MailMerge.Execute
objWord.ActiveDocument.PrintPreview 'Preview
'close the letter template
For Each objDocument In objWord.Documents
If Application.CurrentProject.Path & "\" & objDocument.Name =
ActiveDocument Then
objDocument.close SaveChanges:=False
End If
Next
objWord.Visible = True
objWord.Activate
Exit Sub
WordMergeTest_Exit:
Exit Sub
WordMergeTest_Err:
MsgBox "Error # " & Err.Number & ": " & Err.Description
Set objWord = Nothing
Resume WordMergeTest_Exit
End Sub
merged word document and then closes the original word mail merge doc. It
works fine except the new word doc ends up minimized and my access instance
is the active window.
How can I force the active window to be the new merged word document? I
tried using objWord.Activate but it doesn't set the new merged word document
to the active window.
CODE ****************************
Public Sub WordMergeTest()
On Error GoTo WordMergeTest_Err
Dim objWord As Word.Application, objDocument As Object, ActiveDocument
As String
Set objWord = New Word.Application
ActiveDocument = "c:\data\\Company\myMailMerge.doc"
objWord.Visible = True
objWord.Documents.Open ActiveDocument
objWord.ActiveDocument.MailMerge.Destination = wdSendToNewDocument
objWord.ActiveDocument.MailMerge.SuppressBlankLines = True
objWord.ActiveDocument.MailMerge.Execute
objWord.ActiveDocument.PrintPreview 'Preview
'close the letter template
For Each objDocument In objWord.Documents
If Application.CurrentProject.Path & "\" & objDocument.Name =
ActiveDocument Then
objDocument.close SaveChanges:=False
End If
Next
objWord.Visible = True
objWord.Activate
Exit Sub
WordMergeTest_Exit:
Exit Sub
WordMergeTest_Err:
MsgBox "Error # " & Err.Number & ": " & Err.Description
Set objWord = Nothing
Resume WordMergeTest_Exit
End Sub