以编程方式使用Excel VBA来抑制Outlook电子邮件发送警告消息

时间:2017-09-26 12:57:53

标签: excel vba email outlook

目前,我有一组编码设置为自动发送先前用户输入生成的电子邮件。

当调用它时,它会私下生成/发送电子邮件 - 但要求用户接受&#34; Okay&#34;,&#34;取消&#34;或&#34;帮助&#34;。< / p>

如果用户退出窗格或单击“取消”,则不会发送电子邮件。

有没有办法让程序自动选择命令好吗?

Private Sub sendemail()

Dim outlookapp As Object
Dim mitem As Object
Dim cell As Range
Dim email_ As String
Dim subject_ As String
Dim body_ As String
Dim attach_ As String

'''>>>EMAIL<<<'''
Set outlookapp = CreateObject("Outlook.Application")


email_ = "SomeEmail@Email.com"
subject_ = "General Subject"
body_ = "General Message"

 'create Mail Item and send it
Set mitem = outlookapp.CreateItem(0)
With mitem
    .To = email_
    .Subject = subject_
    .Body = body_
     '.Attachments.Add "C:\FolderName\Filename.txt"
     '.Display 'To Display the message with an option to send or cancel

    .Send 'To auto-send the message
End With

End Sub

我已尝试使用以下代码,但我认为我可能在错误的地方使用它,因为它不成功:

Application.DisplayAlerts = False

'With function/code

Application.DisplayAlerts = True

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情......

Set mitem = outlookapp.CreateItem(0)
With mitem
    .To = email_
    .Subject = subject_
    .Body = body_
     '.Attachments.Add "C:\FolderName\Filename.txt"
     .Display 'To Display the message with an option to send or cancel
     Application.Wait (Now + TimeValue("0:00:02"))
     Application.SendKeys "%s"
End With