There is an official patch from MS that can be downloaded but this is often not allowed by IT depts and needs to be applied to the server rather than an individual machine so what we are looking at here is a workaround.
From this site: http://www.express-soft.com/mailmate/clickyes.html you can download a free program that, when activated, will automatically select the YES option when Outlook pops up the security message
This program can be activated / deactivated by VBA and can therefore be switched off whilst you are not running code and only switched on when you need to automate the sending of emails
The following code should be copied into a module - note This does NOT go in a sub
CODE
' Declare Windows' API functions Private Declare Function RegisterWindowMessage _ Lib "user32" Alias "RegisterWindowMessageA" _ (ByVal lpString As String) As Long
Private Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" (ByVal lpClassName As Any, _ ByVal lpWindowName As Any) As Long
Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) As Long
The following 2 subs switch the program on and off - they should be pasted into the same module as you have put the API declarations in:
CODE
Private Sub Turn_Auto_Yes_On() Dim wnd As Long Dim uClickYes As Long Dim Res As Long uClickYes = RegisterWindowMessage("CLICKYES_SUSPEND_RESUME") wnd = FindWindow("EXCLICKYES_WND", 0&) Res = SendMessage(wnd, uClickYes, 1, 0) End Sub
CODE
Private Sub Turn_Off_Auto_Yes() Dim wnd As Long Dim uClickYes As Long Dim Res As Long uClickYes = RegisterWindowMessage("CLICKYES_SUSPEND_RESUME") wnd = FindWindow("EXCLICKYES_WND", 0&) Res = SendMessage(wnd, uClickYes, 0, 0) End Sub
Once these are in place, you can call them from your Send_Mail sub:
CODE
Sub Send_Mails() Dim appOutLook As Outlook.Application Dim MailOutLook As Outlook.MailItem
'Enables automatic "YES" clicks for Outlook Turn_Auto_YES_On 'set variables for Outlook and a message Set appOutLook = CreateObject("Outlook.Application") Set MailOutLook = appOutLook.CreateItem(olMailItem) With MailOutLook .To = "Name of recipient" .Subject = "Subject Goes Here" .HTMLBody = "This could be a title<br><br>message body and instructions<br>could go here" .Attachments.Add "Path & Filename", olByValue, 1, "Filename To Display" .Send End With
'Turns off the Auto_Yes program Turn_Off_Auto_YES Set MailOutLook = Nothing Set appOutLook = Nothing End Sub
Make sure you reference the correct Outlook Library in Tools>References and then attach the Send_Mails sub to a button. When clicked, it'll send an email via Outlook and whilst the prompt will still appear, YES will be automatically selected