I am using Office 2016 to try and automatically send emails using VBA.
The routines export 1 record at a time to a spreadsheet and the Word mailmerge is invoked using the spreadsheet.
The Word document is then saved as a PDF and the email sent containing the PDF.
The problem I am having is that the routine keeps producing the same dialog box for every record and I would like it to run automatically.
The error I am getting is
Dialog box
The code I am using is
acExport, _
acSpreadsheetTypeExcel12Xml, _
"Updatedetailsone", _
mailmergexls, True
'
' Merge Word document with mailmerge spreadsheet file
'
Set wordApp = CreateObject("Word.Application")
wordApp.Visible = True
Set wordDoc = wordApp.Documents.Open(mailmergedoc)
With wordDoc.MailMerge
.MainDocumentType = wdMailingLetters
.OpenDataSource Name:=mailmergexls, _
ConfirmConversions:=False, _
ReadOnly:=False, _
LinkToSource:=False, _
AddToRecentFiles:=False, _
Connection:="Updatedetailsone"
.Destination = wdSendToNewDocument
.Execute
.MainDocumentType = wdNotAMergeDocument
End With
'
' Delete existing membership form PDF file
' Create new membership form PDF file with current record
'
Kill mailmergepdf
wordApp.ActiveDocument.SaveAs2 mailmergepdf, 17
'
' Close and clean up Word documents
'
For Each wordDoc In wordApp.Documents
wordDoc.Close SaveChanges:=False
Next wordDoc
wordApp.Quit
Set wordDoc = Nothing
Set wordApp = Nothing
Any help will be appreciated.
I would like the routine to automatically select the 1st table without prompting.
Norman Smith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.