Log in

View Full Version : Access the SenderName



Tiger Chen
09-20-2007, 07:05 PM
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.

Charlize
09-20-2007, 11:43 PM
This will give you an idea how you could do this : http://vbaexpress.com/forum/showpost.php?p=113804&postcount=4

Tiger Chen
09-21-2007, 12:50 AM
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&)

Charlize
09-21-2007, 01:26 AM
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.

Tiger Chen
09-21-2007, 01:43 AM
' 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

Charlize
09-21-2007, 02:07 AM
Paste this in a separate module. Now, we need a rule for every new mail and perform the script 'show_msg_box'.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

Tiger Chen
09-22-2007, 01:21 AM
Thanks a lot!

I found Outlook is really not user-friendly! :(