[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MailItem open event

Posted on 2006-06-01
8
Medium Priority
?
1,246 Views
Last Modified: 2008-01-09
Hi everyone,

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 *****
Option Explicit
Public WithEvents vMailItem As Outlook.MailItem
Public Sub InitEvents()
 Dim itm
 For Each itm In Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
  If TypeName(itm) = "MailItem" Then
   Set vMailItem = itm
   MItems.Add vMailItem
  End If
 Next
 Set itm = Nothing
End Sub
Private Sub vMailItem_Open(Cancel As Boolean)
 MsgBox "You opened an item"
End Sub


'***** Standard code module *****
Option Explicit
Public MItems As Collection


'***** ThisOutlookSession *****
Option Explicit
Dim MailEventHandler As New MailEventClass
Private Sub Application_Startup()
 Set MItems = New Collection
 MailEventHandler.InitEvents
End Sub


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.
Any ideas?
Matt
0
Comment
Question by:mvidas
  • 4
  • 4
8 Comments
 
LVL 4

Expert Comment

by:triceice
ID: 16810900
Have you tried using OutlookSpy to see what is going on? "OutlookSpy is the ultimate Outlook developer tool. Integrated directly into Outlook, it provides fast and convenient access to all Outlook Object Model objects, lets you examine values of the properties, call functions, browse object hierarchy and monitor Outlook events. CDO is supported too!" From the website here...http://www.dimastr.com/outspy/
0
 
LVL 35

Author Comment

by:mvidas
ID: 16810965
That does look interesting, but not really what I was looking for. I see I can monitor when events have been run, and it does show the open event, but doesnt explain how to trap it in vba.  My example above is just a sample, I'll be doing much more, I just need to get the basics down before I delve more into it. Thanks though.
0
 
LVL 4

Accepted Solution

by:
triceice earned 2000 total points
ID: 16811041
Don't worry, just offering help with seeing what is going on. This site might have more infomation for you... http://www.outlookcode.com/d/vb.htm and here http://blogs.officezealot.com/legault/articles/2224.aspx   I am not a VBA expert that is the best help I can offer.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 35

Author Comment

by:mvidas
ID: 16811083
That second link actually looks pretty good, I hadn't seen that in the searching I did.  I'm almost done here for the day today, but I'll take a closer look tomorrow and let you know.
0
 
LVL 4

Expert Comment

by:triceice
ID: 16811169
Good luck!
0
 
LVL 35

Author Comment

by:mvidas
ID: 16816198
Got it working 100%.. that second link ( http://blogs.officezealot.com/legault/articles/2224.aspx ) answered all questions I had about this, now time to get started on the real project.  I've looked at Sue Mosher's site before, though I had missed where she talked about a wrapper class which looks like it would have also done what I needed.  In any case it is great info there, after I get this done I'm going to study her site a little more too.

Thanks again!
0
 
LVL 4

Expert Comment

by:triceice
ID: 16816378
Glad I could be of help! Have fun with VBA!
0
 
LVL 35

Author Comment

by:mvidas
ID: 16816504
I always do :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 trialware OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their Exchange server is no longer available or other critical issues with Exchange server or impo…
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question