微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

组织外的 VBA 展望警告收件人:如何避免?

如何解决组织外的 VBA 展望警告收件人:如何避免?

我正在编写一个 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 举报,一经查实,本站将立刻删除。