R
REC
Hello,
I've got code to perform a mail merge using an Excel spreadsheet as the data
source. The spreadsheet will only have one worksheet, but the name of the
worksheet is variable. Is there a way to let the mail merge automatically
select the one and only worksheet? Thanks for your help. Here is my code:
'Configure mail merge data source parameters:
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:=strDataSource, _
ConfirmConversions:=False, _
ReadOnly:=False, _
LinkToSource:=True, _
AddToRecentFiles:=False, _
PasswordDocument:="", _
PasswordTemplate:="", _
WritePasswordDocument:="", _
WritePasswordTemplate:="", _
Revert:=False, _
Format:=wdOpenFormatAuto, _
Connection:="", _
SQLStatement:="SELECT * FROM `myWorksheetNameHere`",
SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
'Start mail merge:
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
I've got code to perform a mail merge using an Excel spreadsheet as the data
source. The spreadsheet will only have one worksheet, but the name of the
worksheet is variable. Is there a way to let the mail merge automatically
select the one and only worksheet? Thanks for your help. Here is my code:
'Configure mail merge data source parameters:
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:=strDataSource, _
ConfirmConversions:=False, _
ReadOnly:=False, _
LinkToSource:=True, _
AddToRecentFiles:=False, _
PasswordDocument:="", _
PasswordTemplate:="", _
WritePasswordDocument:="", _
WritePasswordTemplate:="", _
Revert:=False, _
Format:=wdOpenFormatAuto, _
Connection:="", _
SQLStatement:="SELECT * FROM `myWorksheetNameHere`",
SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
'Start mail merge:
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With