1

我有一个循环来发送大约 75 封电子邮件,每封电子邮件都有一个针对每个收件人的单独附件。这行得通,但我想知道如何创建所有这些,并一次性发送它们,而不是一次喂它们。

我知道我可以使用.display而不是.send在 Outlook 中显示电子邮件,但是有没有办法使用 VBA 暂时禁用发送电子邮件,然后在创建所有邮件后启用它?

我的代码看起来像这样 -

Dim employee_name As Variant
Dim file_path As String
Dim file_ext As String
Dim AGENT_FILE As String
Dim e As Variant
Dim email As Variant
Dim a As Integer

a = "0"
Sheets("EMAILS").Select
employee_name = Range("A1:A76").Value

file_path = "H:\Email TEST\"
file_ext = ".xlsx"

Dim OutApp As Object
Dim OutMail As Object
Dim distributionList As String

Set OutApp = CreateObject("Outlook.Application")

For Each e In employee_name

    If e <> "" Then 

        Set OutMail = OutApp.CreateItem(0)

        With Sheets("EMAILS").Select
            a = a + 1
            email = Range("B" & a).Value
            AGENT_FILE = file_path & e & file_ext

            On Error Resume Next
            With OutMail
                .To = email
                .CC = ""
                .BCC = ""
                .Subject = "Daily Stats"
                .Body = "Hello ," & vbCrLf & _
                  vbCrLf & _
                  "Attached are your daily stats." & vbCrLf & _
                  vbCrLf & _
                  "Regards, " & vbCrLf & _
                  "Oliver Lockett"
                .Attachments.Add AGENT_FILE
                .send
            End With
        End With

        Set OutMail = Nothing

    End If

Next

Set OutApp = Nothing
4

2 回答 2

2

几年前我也有类似的东西...

我更喜欢使用 .save 而不是 .send。因此,所有电子邮件都保存在草稿下......一旦所有电子邮件都被保存......我在 Outlook 中有一个宏来发送所有草稿......这可以在这里实现

http://www.techrepublic.com/forum/questions/101-309127/send-all-mails-from-my-drafts-folder-at-one-go-in-outlook-2003

于 2013-06-25T12:15:43.500 回答
0

你为什么想这么做?发送是异步的,它不会阻塞你的代码。

于 2013-06-25T18:42:22.313 回答