×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VBA Visual Basic for Applications (Microsoft) FAQ

Office / VBA General

How do I bypass the Outlook security message when trying to automate emails by xlbo
Posted: 23 Jun 04

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

Hope you find this as uaseful as I !!

Back to VBA Visual Basic for Applications (Microsoft) FAQ Index
Back to VBA Visual Basic for Applications (Microsoft) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close