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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel data to Word Email Merge 1

Status
Not open for further replies.

SPYatwork

Technical User
Jun 21, 2005
10
GB
Guy's I'd really appreciate some help!
I have Office 2010 and an Excel sheet that I have used as the source in a Word Email merge.
I am trying to avoid the user having to open Word & run the Merge manually by providing some code in Excel to perform the task & create the emails.
The code I have fails with runtime 5174 error. Application or Object defined error at the highlighted point below.

Any help much appreciated!

Sub xxmerge()
Dim WordApp As Object
Dim fPath As String
fPath = "C:\Users\sp\desktop\MMX.docx"
Set WordApp = CreateObject("word.application")
WordApp.Documents.Open (fPath)
WordApp.Visible = True
ActiveDocument.Mailmerge.MainDocumentType = wdEMail
ActiveDocument.Mailmerge.OpenDataSource Name:= _
"C:\Users\SP\desktop\Merge File.xlsx", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Users\sp\desktop\Merge File.xlsx;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=37;Jet OLEDBat" _
, SQLStatement:="SELECT * FROM `Sheet1$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
With ActiveDocument.Mailmerge
.Destination = wdSendToemail
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End Sub
 


hi,

WHAT statement?

NOTHING is highlighted.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Sorry, this is the line it fails at:
ActiveDocument.Mailmerge.MainDocumentType = wdEMail
 


If you do not have a reference set in Tools > References, to Microsoft Word n.m Object Library, then the VB Editor cannot resolve the constant wdEMail, which is 4.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Guy's my code now fails at:
ActiveDocument.Mailmerge.OpenDataSource Name:= _
"C:\Users\SP\desktop\Merge File.xlsx", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Users\sp\desktop\Merge File.xlsx;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=37;Jet OLEDBat" _
, SQLStatement:="SELECT * FROM `Sheet1$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess

Any ideas?
Thanks
 


I would remove ALL the Optional arguments, since MANY of them are wd... Word Constants, which you appear NOT to have a reference set for. See my previous post regarding this very issue.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top