Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Forms / December 2005

Tip: Looking for answers? Try searching our database.

How to inspect Inbox messages with VBA?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
deko - 30 Dec 2005 01:49 GMT
I use the following to loop through email messages in the Outlook Inbox:

Dim olmi as Outlook.MailItem
Dim olfi as Outlook.Items
Dim olr As Outlook.Recipient
Dim olrs As Outlook.Recipients

Set olfi = olFolder.Items

For Each olmi In olfi
   'match recipient address
   Set olrs = olmi.Recipients
   For Each olr In olrs 'check every recipient the message was sent to
       Debug.Print "checking olr.Address [" & olr.Address & "]"
           If olr.Address = strAddress And olmi.SenderEmailAddress <>
olr.Address Then
               Debug.Print "Found matching Recipient address!"
           End If
       End If
   Next
Next

The problem is when users have encrypted messages, or messages of SYSTEM
type (e.g. an undeliverable alert from the System Administrator) in their
Inbox.  When one of these messages is encountered, a Type Mismatch error is
returned and the code exits the loop.  I've tried a On Error Resume Next,
but no luck.

Is there a way to test for encrypted or SYSTEM type messages?  It appears
these types of messages are not Outlook.MailItems and therefore the error
occurs as soon as the "For Each olmi In olfi" line is executed.  I'm
thinking I could insert a line of code above that For Each statement to test
if the message can or cannot be inspected... ?  Other options?

Thanks in advance.
Ken Slovak - [MVP - Outlook] - 30 Dec 2005 14:30 GMT
You can check for item.Class or item.MessageClass. For Class a mail item
would return olMail.

You can do that by declaring your mail item as Object and skipping the
processing if Class <> olMail. Of course that would need to late bind any
properties of the Object. You could assign a MailItem from the Object if the
test passes.

Signed or encrypted items might return olMail but their MessageClass would
not be "IPM.Note" but something else, perhaps .Note.something or some custom
message class.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

>I use the following to loop through email messages in the Outlook Inbox:
>
[quoted text clipped - 31 lines]
>
> Thanks in advance.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.