
VBA using a array as a datasource for a mail merge in msword.
First, thank you in advance for the feedback, second i am not programmer but putting my best foot forward.
I have created a VBA macro in Excel that reads an excel table and creates a few 2D arrays out of the initial table. I had the macro working perfectly using an excel table as the datasource for a MSword Mail Merge - partial code below.
I have a MS word document properly formatted containing all the merge fields (thought this may make this easier) and now I need to use one of the created arrays as the mail merge Data source, actually I only need the last record to be merged. is there a method of using the Array as a data source? or should a different method be used? Any assistance is greatly appreciated, thank you in advance.
objDoc.MailMerge.MainDocumentType = wdFormLetters
objDoc.MailMerge.OpenDataSource Name:= _
"C:\Program Files\Excel\Data\ExcelDataFile.xlsm", _
ConfirmConversions:=False, _
ReadOnly:=True, _
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:\Program Files\Excel\Data\ExcelDataSource.xlsm;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:", _
SQLStatement:="SELECT * FROM `ProductionRequest$`", SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
'objDoc.MailMerge.DataSource.ActiveRecord = wdFirstRecord
objDoc.MailMerge.DataSource.ActiveRecord = wdLastRecord
objDoc.MailMerge.ViewMailMergeFieldCodes = wdToggle
'objDoc.MailMerge.Execute
Microsoft 365 and Office | Development | Other
