Mail Merge Automation
I'm trying to automate a merge from an Excel spreadsheet that has a
named range named "Database" into a Word document with merge codes
named "M_1", "M_2", "M_3", etc.
When merging manually, it works, however when I run it from a macro,
even a macro recorded from a scenario that just worked, it gives me an
"Invalid Merge Field" dialog box or opens up the dialog box where it
asks for me to pick a Table, depending on if I run the code from Excel
or Word.
Anyway, here's the line of code in my Excel vba that I'm sure is
causing all my frustration:
objWord.ActiveDocument.MailMerge.OpenDataSource
NAME:=\"C:\TEXT.XLS\", _
ConfirmConversions:=True, _
ReadOnly:=False, _
LINKTOSOURCE:=TRUE, _
AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", _
WritePasswordDocument:="", _
WritePasswordTemplate:="", _
Revert:=False, _
Format:=wdOpenFormatAuto, _
CONNECTION:=\"DATABASE\", _
* SQLStatement:="SELECT * FROM c:\test.xls", _*
SQLStatement1:="", _
SubType:=wdMergeSubTypeOther
I emphasized the parts of the code I believe are required. I think all
the other lines can be removed, but I've left them in place for now
since removing them doesn't seem to make a difference.
So what's it look like I'm doing wrong?
If it helps, I'll make Excel and Word test files to upload. I would've
done it now, but there's quite a bit of company info I'd need to trim
out before posting it.
--
leaftye
|