I'm trying to create a Command Button in an Excel file that will do a Word mail merge. When I execute the code, the Word document opens and tries to open another copy of the Excel file as the data source and then gets hung up. How can I get the Word merge document to recognize the open spreadsheet that the Command Button on as the data source for the merge?
Thanks, Kopy
Here's my code:
==========================================================
Dim WordApp As Object
Set WordApp = CreateObject("Word.Application"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
WordApp.Documents.Open ("C:\Comp\2002 Supervisor Planning Worksheet Merge.doc"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
WordApp.Visible = True
WordApp.ActiveDocument.mailmerge.MainDocumentType = wdFormLetters
WordApp.ActiveDocument.mailmerge.OpenDataSource Name:="C:\Comp\2003MeritToolMikeTest.xls"
With WordApp.ActiveDocument.mailmerge
WordApp.Destination = wdsendtonewdocument
WordApp.MailAsAttachment = False
WordApp.MailAddressFieldName = ""
WordApp.MailSubject = ""
WordApp.suppressblanklines = True
With WordApp.DataSource
WordApp.FirstRecord = wdDefaultFirstRecord
WordApp.LastRecord = wdDefaultLastRecord
End With
WordApp.Execute Pause:=True
End With
Thanks, Kopy
Here's my code:
==========================================================
Dim WordApp As Object
Set WordApp = CreateObject("Word.Application"
WordApp.Documents.Open ("C:\Comp\2002 Supervisor Planning Worksheet Merge.doc"
WordApp.Visible = True
WordApp.ActiveDocument.mailmerge.MainDocumentType = wdFormLetters
WordApp.ActiveDocument.mailmerge.OpenDataSource Name:="C:\Comp\2003MeritToolMikeTest.xls"
With WordApp.ActiveDocument.mailmerge
WordApp.Destination = wdsendtonewdocument
WordApp.MailAsAttachment = False
WordApp.MailAddressFieldName = ""
WordApp.MailSubject = ""
WordApp.suppressblanklines = True
With WordApp.DataSource
WordApp.FirstRecord = wdDefaultFirstRecord
WordApp.LastRecord = wdDefaultLastRecord
End With
WordApp.Execute Pause:=True
End With