MailItem open event
Posted on 2006-06-01
I'm trying to figure out how to trap the opening/double-clicking of a message in my inbox. Can someone help steer me in the right direction?
Here is what I have in my vbaproject.otm file:
'***** Class Module called MailEventClass *****
Public WithEvents vMailItem As Outlook.MailItem
Public Sub InitEvents()
For Each itm In Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
If TypeName(itm) = "MailItem" Then
Set vMailItem = itm
Set itm = Nothing
Private Sub vMailItem_Open(Cancel As Boolean)
MsgBox "You opened an item"
'***** Standard code module *****
Public MItems As Collection
'***** ThisOutlookSession *****
Dim MailEventHandler As New MailEventClass
Private Sub Application_Startup()
Set MItems = New Collection
I've tried just about every variation I can think of, but the event only triggers on the last message in my inbox (since it was the last item to be set as vMailItem). I'm sure this is a simple thing, just cant get my head around it.