user5889203
user5889203

Reputation:

How do I bypass outlook alerts when trying to get user infromation?

I am trying to get username, user email, user department, and user location from outlook to populate an excel user form.

That code works without issue. The problem I am having is this: I get the popup from Excel saying "A program is trying to access e-mail address information stored in Outlook. If this is unexpected, click Deny and verify your antivirus software is up to date."

I found some code that is supposed to suppress this popup, but it doesn't appear to be working. Below is the procedure that is calling using the procedure. I have put the call to the "Turn_Auto_Yes_On" procedure multiple times to see if it works with any of the calls. Turn_Auto_yes_On is successfully executed, but seems to have no effect as I still get the outlook message after execution.

I am stuck here and have gone to multiple sites for answers, and I have found none. Any help would be much appreciated.

Function fill_Outlook_Info() As Boolean


Application.DisplayAlerts = False
    Call Turn_Auto_Yes_On
    Set OL = CreateObject("outlook.application")

    Call Turn_Auto_Yes_On
    Set olAllUsers = OL.Session.AddressLists.Item("All Users").AddressEntries

    Call Turn_Auto_Yes_On
    s_OutlookUser = OL.Session.CurrentUser.Name

    Call Turn_Auto_Yes_On
    Set oentry = olAllUsers.Item(s_OutlookUser)

    Call Turn_Auto_Yes_On
    Set oExchUser = oentry.GetExchangeUser() 
    v_department = oExchUser.DEPARTMENT
    v_Email = oExchUser.PrimarySmtpAddress
    s_OutlookCity = oExchUser.city
End Function

and this is the code that is supposed to bypass outlook's alerts

Option Explicit

'these declarations are to access the RegisterWindowsMessage which is used to send "yes" to outlook

Public OL, olAllUsers, oExchUser, oentry As Object
Public v_Email As Variant 'v_department
'Public s_OutlookUser As String
Public Declare Function RegisterWindowMessage Lib "User32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Public Declare Function FindWindow Lib "User32" _
Alias "FindWindowA" (ByVal lpClassName As Any, _
ByVal lpWindowName As Any) As Long
Public Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long



Public 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

Public 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

Upvotes: 0

Views: 192

Answers (1)

Todd Page
Todd Page

Reputation: 173

While not specific to this exact use case, I have gotten around similar outlook "manual confirmation" and "Outlook security" issues by using Outlook Redemption.

Outlook Redemption works around limitations imposed by the Outlook Security Patch plus provides a number of objects and functions to work with properties and functionality not exposed through the Outlook object model.

With Outlook Redemption you can [...] Make your code runs unaffected by the Security Patch.

My particular use case was automatically sending outlook e-mails from python. I had the same issue with the user pop-up and this did the trick.

Upvotes: 2

Related Questions