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

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

当它被调用时,它私下生成/发送一封电子邮件 – 但要求用户接受“好”,“取消”或“帮助”。

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

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

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 

你可以尝试这样的事情…

 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