SQL statement when automating a Mail Merge

tianimo

New Member
Joined
Sep 29, 2006
Messages
9
In Office 2007 I'm trying to trigger a Mail Merge in Word from Excel. I have enabled the right library references I think to allow me to manipulate Word from within the Excel sub.

Given the data I need for the Mail Merge is stored within a sheet within a workbook, I need to select the data from the sheet. I've got a "SELECT * FROM SheetName" in the "SQL Statement" description (see below). However when I run the macro, it opens the document but then says:

"Object doesn't support this property or method".

I'm not sure what's causing this problem? The code below is basically what is generated when I record the process of setting up a Mail Merge in a document.

Thanks.

-----------------------------------------------

Set appWd = CreateObject("Word.Application")
appWd.Visible = True

appWd.Documents.Open Filename:="\\ldn-shared-a\Docs\Test Mail Merge.docx"
appWd.MailMerge.OpenDataSource _
Name:="\\ldn-shared-a\Docs\SQLExtract.xlsm", _
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=\\ldn-shared-a\Docs\SQLExtract.xlsm;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;", _
SQLStatement:="SELECT * FROM `MailMergedata$`", SQLStatement1:="", SubType:=wdMergeSubTypeAccess
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,224,583
Messages
6,179,671
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top