邮件合并电子邮件宏

时间:2015-06-17 11:14:32

标签: vba email ms-access outlook-vba

我正在尝试创建一个宏来发送word文档到每个文档4封电子邮件,每个都来自它自己的字段

e.g。 supplier1mail,supplier2mail等通常会在每批约10个文档中发送,数据从访问数据库中提取,电子邮件通过outlook发送。

主题行将始终相同,不需要正文。任何帮助将不胜感激,因为这是我第一次真正看到 VBA。 感谢。

1 个答案:

答案 0 :(得分:1)

为了让你开始,这就是我的做法(之前,设置你的邮件在Word中):

Sub MergeToEmail()
Dim DisPTxT As String

    Dim bDone As Boolean
    bDone = False

    Do While bDone = False

        ActiveDocument.Fields.Update

        With ActiveDocument.MailMerge
            .MailAddressFieldName = "Mail"
            .Destination = wdSendToEmail
            .SuppressBlankLines = True
            ' You can modify the text "Enter Your Subject Here" or
            ' remove the following line if you do not want a subject
            .MailSubject = "Samedi 26 Avril 2014"
            With .DataSource
                .FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
                .LastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
            End With
            .Execute Pause:=False
        End With

        If ActiveDocument.MailMerge.DataSource.ActiveRecord = _
            ActiveDocument.MailMerge.DataSource.RecordCount Then
            bDone = True
        End If
        ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
    Loop
End Sub