简体   繁体   English

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

[英]Programmatically supress Outlook email send warning message using Excel VBA

Currently, I have a group of coding that is set to auto-send an email generated on prior user input. 目前,我有一组编码,这些编码设置为自动发送在先前用户输入时生成的电子邮件。

When this is called, it privately generates/sends an email - but asks the user accept "Okay", "Cancel", or "Help". 调用此方法时,它会私下生成/发送电子邮件-但要求用户接受“确定”,“取消”或“帮助”。

If the user exits the pane or clicks Cancel, the email is not sent. 如果用户退出窗格或单击“取消”,则不会发送电子邮件。

Is there a way to have the program auto-select the command Okay? 有办法让程序自动选择命令好吗?

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

I've tried using the following code, but think I may be using it in the wrong places as it has been unsuccessful: 我尝试使用以下代码,但由于未成功,我认为我可能在错误的地方使用它:

Application.DisplayAlerts = False

'With function/code

Application.DisplayAlerts = True

You may try something like this... 您可以尝试这样的事情...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM