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
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