On click event for mail item selection

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I have a mail folder called MyInfo when I click on a mail item inside that
folder I want to execute vba code to go and grab details from a SQL Server
Database,
My problem is I cant find an "OnClick" event when a mail item is mouse clicked
Can any one help!
 
When you click on an item in a folder it changes the selection. You can use
the Explorer.SelectionChange() event for what you want.

Instantiate an Explorer object declared WithEvents to handle the
SelectionChange() event and instantiate that Explorer object as the
ActiveExplorer.

When that event fires you can get the Explorer.Selection collection, which
can be iterated to handle all selected items. If there's only 1 selected
item then Selection.Item(1) will get that item in the event handler.
 
Im don't know how to perform the following:

"Instantiate an Explorer object declared WithEvents to handle the
SelectionChange() event and instantiate that Explorer object as the
ActiveExplorer."

Do you have an example!
_______________________________________________________________
 
You can put the code in the ThisOutlookSession class and use something like
this:

Dim WithEvents oExpl As Outlook.Explorer

Private Sub Application_Startup()
Set oExpl = Application.ActiveExplorer
End Sub

Private Sub oExpl_SelectionChange()
Dim colSelection As Outlook.Selection
Dim obj As Object
Dim oMail As Outlook.MailItem

Set colSelection = oExpl.Selection
For Each obj In colSelection
If obj.Class = olMail Then
Set oMail = obj
' is a selected mail item do whatever with it
End If
Next
End Sub
 
Back
Top