ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Mail Merge Automation (https://www.excelbanter.com/excel-discussion-misc-queries/117885-mail-merge-automation.html)

leaftye

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

leaftye

Mail Merge Automation
 

Bump for help heading into a slow holiday. Please help me find a
solution to use tomorrow while I'm bored out of my mind tomorrow at
work!




--
leaftye


All times are GMT +1. The time now is 05:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com