Hi jaslake ... thank you for your kind offer.
The mail merge works fine. If I manually call up the mail document it populates nicely and produces a final document no problems.
Its the launching of the .dot document from my Excel application which is causing me the grief.
From a user form, the user selects the report they wish to have printed by clicking a button.
Private Sub tb1_cue_dia_Click()
tb1_cue_dia.Value = True
If varhold.Range("I16") > 0 Then
varhold.Range("A36") = "\DT\v5\DT-CUE5.dot"
Call merge
End If
varhold.Range("A36") = "DR\v5\DR-CUE5.dot"
Call merge
End Sub
Once it is know which report the user wants printed, the Word lauch macro is started ...
Option Explicit
Dim objword As Object
Dim odoc As Object
Dim odoc2 As Object
Const wdSendToNewDocument = 0
Dim mypath As String
Sub merge()
Dim fName As String
Set objword = CreateObject("Word.Application")
objword.DisplayAlerts = True
fName = Sheets("varhold").Range("A37").Text ' A37 = CONCATENATE("E:\Integrity12\Reports\",A36) = E:\Integrity12\Reports\DR\v5\DR-CUL5.dot
Set odoc = objword.Documents.Open(fName) 'hangs here. Even if the user approves SQL request, code will hang as per original post
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"
Set objword = Nothing
Set odoc = Nothing
Set odoc2 = Nothing
End Sub
I'm going to have to edit the the main application (Excel) file as it's quite a big application. The mailmerge data is a separate workbook, needing some editting of confidential information.
I'll see what I can do.
Jenn
Bookmarks