简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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