Consulting

Results 1 to 7 of 7

Thread: Access the SenderName

  1. #1

    Access the SenderName

    When I want to return the SenderName in my own VBA code, OL will pop up a message "...some code is trying to access the mail address... do you allow...". Can we turn this alert off?

    I search the answer on internet, I found too much questions on this but no good solution yet.

    There is a software named "..ClickYes..." can remove the alert when it runs.

    Does anybody know how to disable the alert in VBA? Thanks.

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    This will give you an idea how you could do this : http://vbaexpress.com/forum/showpost...04&postcount=4

  3. #3
    Hi Charlize, Thanks for your reply!
    I agree this should work. However, I just copy your code into my outlook code, it doesn't work.
    I use debug.print to return wnd and res. Both are 0. I'm not familar with API. Do you know why?

    Do we need to change this statement:
    wnd = FindWindow("EXCLICKYES_WND", 0&)

  4. #4
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    If you would show your code, it would certainly help to see what's going on. And that clickyes program must, of course, be present and running.

  5. #5
    [VBA]
    ' Declare Windows' API functions
    ' To be used with ExpressClick Yes
    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

    'These are used by the utility ClickYes Freeware
    Public wnd As Long
    Public uClickYes As Long
    Public Res As Long

    Private Sub Application_NewMail()
    Dim myOlApp As Outlook.Application
    Dim myItem As Outlook.MailItem
    Dim myNamespace As Outlook.NameSpace
    Dim myFolder As Outlook.MAPIFolder
    Dim mySender As String
    Set myOlApp = CreateObject("Outlook.Application")
    Set myNamespace = myOlApp.GetNamespace("MAPI")
    Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
    Set myItem = myFolder.Items(myFolder.Items.Count)

    Call PrepareClickYes
    mySender = myItem.SenderName
    Call PerformClickYes

    MsgBox myItem.Subject & mySender & myItem.ReceivedTime
    End Sub

    Sub PrepareClickYes()
    'called before attempting to manipulate a message
    uClickYes = RegisterWindowMessage("CLICKYES_SUSPEND_RESUME")
    wnd = FindWindow("EXCLICKYES_WND", 0&)
    Debug.Print wnd
    Res = SendMessage(wnd, uClickYes, 1, 0)
    End Sub
    Sub PerformClickYes()
    'called directly after the code that manipulates
    'a message. Clicks the yes and places the ClickYes utility
    'back in suspend mode. When some other routine (that's not
    'controlled by you) wants to do something with your
    'messages, you still get that warning.
    Res = SendMessage(wnd, uClickYes, 0, 0)
    Debug.Print "res " & Res
    End Sub

    [/VBA]

  6. #6
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Paste this in a separate module. Now, we need a rule for every new mail and perform the script 'show_msg_box'.[VBA]Option Explicit
    ' Declare Windows' API functions
    ' To be used with ExpressClick Yes
    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

    'These are used by the utility ClickYes Freeware
    Public wnd As Long
    Public uClickYes As Long
    Public Res As Long
    Sub show_msg_box(myItem As Outlook.MailItem)
    Dim mySender As String
    Call PrepareClickYes
    mySender = myItem.SenderName
    Call PerformClickYes
    MsgBox "- From : " & mySender & vbCrLf & _
    "- Subject : " & myItem.Subject & vbCrLf & _
    "- Received : " & myItem.ReceivedTime, vbInformation
    End Sub
    Sub PrepareClickYes()
    'called before attempting to manipulate a message
    uClickYes = RegisterWindowMessage("CLICKYES_SUSPEND_RESUME")
    wnd = FindWindow("EXCLICKYES_WND", 0&)
    Debug.Print wnd
    Res = SendMessage(wnd, uClickYes, 1, 0)
    End Sub
    Sub PerformClickYes()
    'called directly after the code that manipulates
    'a message. Clicks the yes and places the ClickYes utility
    'back in suspend mode. When some other routine (that's not
    'controlled by you) wants to do something with your
    'messages, you still get that warning.
    Res = SendMessage(wnd, uClickYes, 0, 0)
    Debug.Print "res " & Res
    End Sub[/VBA]

  7. #7
    Thanks a lot!

    I found Outlook is really not user-friendly!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •