问题描述
我正在编写一个 VBA Excel 脚本,用 Outlook 将电子邮件发送给不同的收件人,包括我组织外部的收件人。我遵循了 Ron DeBrujin 的指南,它适用于与我的帐户相同的组织中的收件人,例如此处设置为“lineello@mycorporation.com”。
Sub Mail_small_Text_Change_Account()
Dim OutApp As outlook.application
Dim OutMail As Outlook.MailItem
Dim OutAccount As Outlook.Account
Dim strbody As String
Set OutApp = CreateObject("outlook.application")
Set OutMail = OutApp.CreateItem(olMailItem)
Set OutAccount = OutApp.Session.Accounts("linello@mycorporation.com")
strbody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"
On Error Resume Next
With OutMail
.To = "anotheruser@anothercorporation.com"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = strbody
.SendUsingAccount = OutAccount
.Send
End With
On Error GoTo 0
Set OutMail = nothing
Set OutApp = nothing
Set OutAccount = nothing
End Sub
不幸的是,如果一个或多个收件人属于不同的组织,Outlook 会提示警告。警告提示“收件人在组织外”,要求用户明确选择要发送邮件的收件人,然后按“确定”。
我尝试暂时禁用警报和警告:
Application.displayAlerts = False
Application.EnableEvents = False
With OutMail
.To = "anotheruser@anothercorporation.com"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = strbody
.SendUsingAccount = OutAccount
.Send
End With
Application.displayAlerts = True
Application.EnableEvents = True
但我没有走运:提示消息框仍然出现,要求我确认我打算向组织外发送电子邮件。 考虑到我需要发送邮件的大量地址,这种手动操作非常烦人和不需要。
我想知道 VBA 中是否有办法避免此警告框,然后继续发送电子邮件。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)