Hello All,
This is my first post here. I have no formal education in VB, but with the help of internet based forums like this one and the helpful members that use, I have managed over a course of two years to develop an Excel based application that wonderful potential. I am nearing completion, but have hit a significant hurdle that most have been unable to provide assistance with to over come.
My Excel application unites a data from a worksheet with Word's mail merge functions. The desire is that with a push of a button in Excel, the completed mail merge document will be completed, saved and printed, with no user interaction other than the initial button push. I have developed the mail merge document, and set it up effectively to the dataset with the appropriate filters and sorting actions needed via Word's GUI.
And now I'm stuck. The integration.
This is the code that I have established so far.
Sub report()
Dim ObjWord As Object
Set ObjWord = CreateObject("Word.Application")
ObjWord.Documents.Open ("E:\SA09-02\Reports10\SO10-DR_HPL.Doc"), vbNormalFocus
ObjWord.Visible = True
ObjWord.MailMerge.OpenDataSource Name:="E:\SA09-02\Reports\reportdata.xls" _
, ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:="", SQLStatement:="", SQLStatement1:=""
End Sub
The document opens, but without the mail merge functionality. It results in and error with the red highlighted code "Object doesn't support this property or method."
It also does not address the specific worksheet from within the workbook where the data is.
I can only assume that this is the same line in which the SQL for filtering and sorting is applied as well. The Word prompt requesting approval to use SQL prior to opening the merge document is:
SELECT * FROM 'CONTROL_1$' WHERE 'subresp' = 'HPL1' AND 'Type' = 'DR' ORDER BY 'Start' ASC, 'Unit$' ASC
I'm not sure how to integrate that into the code.
The next would be how to bypass the user needing to push the "Merge To New Document" button to get actually prepare the document.
And of course, returning the user back to the Excel application after the report has been acknowledged after printing.
I am desperate for help at this point so close to the completion of my application, so I hope someone can help me here. I do not have the strongest grasp of highly complex VBA, so my apologies in advance if my blondness seems apparent, and ask for patience.
Thanks you!!!
Jenn