Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel to Word Mail Merge Issue

Status
Not open for further replies.

kopy

Technical User
May 30, 2002
141
US
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")
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top