Share via

Mailmerge problem

Anonymous
2024-08-17T07:08:42+00:00

Hi all,

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

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

Microsoft 365 and Office | Install, redeem, activate | Other | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-08-17T09:00:06+00:00

    Hi StormingNorman41,

    Thanks for your post in Microsoft Community.

    Based on your description, it seems like that you encountering some macro related issues.

    Well, there is a better place to publish which is Stack Overflow.

    Ask vba programming questions to Stack Overflow by using the vba tag along with any other relevant tags.

    Please note that Stack Overflow includes guidelines, such as requesting a descriptive title, a complete and concise problem description, and sufficient details to reproduce your problem. Feature requests or questions that are too broad are considered off-topic.

    Disclaimer: Microsoft provides no assurances and/or warranties, implied or otherwise, and is not responsible for the information you receive from the third-party linked sites or any support related to technology.

    I can't help you, but I'll leave this question open in case one of our great volunteers has ideas for you.

    Best regards,

    Thomas C - MSFT | Microsoft Community Support Specialist

    Was this answer helpful?

    0 comments No comments