excel - 如何避免对组织外的收件人发出警告?
问题描述
我正在编写一个 VBA Excel 脚本,以便将带有 Outlook 的电子邮件发送给不同的收件人,包括我组织之外的收件人。
我遵循了Ron DeBrujin的指南,它适用于与我的帐户在同一组织中的收件人,例如设置为“linello@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 会提示警告。
“组织外的收件人”
它要求用户明确选择要发送消息的收件人,然后按 OK。
我尝试通过以下方式暂时禁用警报和警告:
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中有没有办法避免这个警告框?
解决方案
推荐阅读
- java - 基于属性值的 Jackson XML 绑定元素
- excel - 基于唯一标识符生成主表,其中包含每个表/工作表中数据的列
- solaris - 在 QEMU 上模拟 Solaris 10 SPARC
- elasticsearch - 带有空格的 Elasticsearch 术语查询不起作用
- javascript - react-datepicker,默认为monthsShown问题
- javascript - 更改显示在?上的图像的有效方法
- javascript - JSON 数据部分无法更改
- c# - 使用 linq 为新列表赋值
- asp.net-core - 无法将 VS 项目从 ASP.NET Core 2.1 升级到 2.2
- ms-access - 特定数字的自动递增字母