I am using this code in my Excel VBA application to execute a mail merge routine in MS Word.
Sub merge()
Set objword = Nothing
Set odoc = Nothing
Set Odoc2 = Nothing
Set objword = CreateObject("Word.Application")
objword.DisplayAlerts = True
Set odoc = objword.Documents.Open(Range("A37").Value)
objword.Visible = True
'Odoc.Application.Visible = True
odoc.MailMerge.Destination = wdsendtonewdocument
odoc.MailMerge.Execute
Set Odoc2 = odoc.Application.Documents("Catalog1")
odoc.Close False
mypath = "e:\Integrity12\Workorders\" & Format(Range("A26"), "ddd dd-mmm-yy")
If Len(Dir(mypath, vbDirectory)) = 0 Then MkDir mypath
Odoc2.SaveAs mypath & "\" & (Range("A36").Value & ".doc")
objword.DisplayAlerts = True
objword.Application.Quit True
AppActivate "Microsoft Excel"
End Sub
The application hangs at the line in red. I am not able to manipulate anything in Excel at this point, it does not react. Microsoft Word is not visible, yet it is there in Task Manager. I have to close Word via task Manager to regain control.
The value in worksheets("varhold").range("A37") is E:\Integrity12\Reports\DR\DR_CUL2.dot
Any ideas as to what I am doing wrong?
Bookmarks