我有一个循环来发送大约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
答案 0 :(得分:2)
我更喜欢使用.save代替.send。因为所有电子邮件都保存在草稿下....一旦所有电子邮件都被保存....我在Outlook中有一个宏来发送所有草稿...... 这可以在这里实现
答案 1 :(得分:0)
你为什么要那样做?发送是异步的,它不会阻止您的代码。