D
deko
I need to loop through the Outlook Inbox (or other OL folder) and inspect
the recipient address of each message. The problem is when an encrypted or
"undeliverable message" is encountered in the folder - a Type Mismatch error
is returned. Is there a way to identify these non-MailItem messages and
skip over them?
Here's my code (using automation from Access):
Dim olapp as Outlook.Application
Dim olmi as Outlook.MailItem
Dim olr As Outlook.Recipient
Dim olrs As Outlook.Recipients
Dim olFolder As Outlook.MAPIFolder
Dim olfi As Outlook.Items
Dim olns As Outlook.NameSpace
Set olapp = New Outlook.Application
Set olns = olapp.GetNamespace("MAPI")
Set olFolder = olns.PickFolder
Set olfi = olFolder.Items
I want to inspect each olmi in olfi. The problem is there are sometimes
items in the olfi collection that are not olmi's - e.g. ReportItems
(undeliverable messages), and encrypted messages (not sure what these are).
Normally, I can just loop like this:
For Each olmi In olfi
'match recipient address with strAddress
Set olrs = olmi.Recipients
For Each olr In olrs 'check every recipient the message was sent to
If olr.Address = strAddress Then
Debug.Print "Found matching Recipient address!"
End If
Next
Next
But if a non-olmi item is encountered, I get a Type Mismatch error. Is
there a way to test to make sure the item is an olmi before entering the For
Each loop? In pseudo code, it might look something like this:
For Each item In olfi
If item <> olmi then
GoTo Next_Item
Else
Set olrs = olmi.Recipients
For Each olr In olrs 'check every recipient the message was sent
to
If olr.Address = strAddress Then
Debug.Print "Found matching Recipient address!"
End If
Next
End if
Next_Item:
Next
Other suggestions?
Thanks in advance.
the recipient address of each message. The problem is when an encrypted or
"undeliverable message" is encountered in the folder - a Type Mismatch error
is returned. Is there a way to identify these non-MailItem messages and
skip over them?
Here's my code (using automation from Access):
Dim olapp as Outlook.Application
Dim olmi as Outlook.MailItem
Dim olr As Outlook.Recipient
Dim olrs As Outlook.Recipients
Dim olFolder As Outlook.MAPIFolder
Dim olfi As Outlook.Items
Dim olns As Outlook.NameSpace
Set olapp = New Outlook.Application
Set olns = olapp.GetNamespace("MAPI")
Set olFolder = olns.PickFolder
Set olfi = olFolder.Items
I want to inspect each olmi in olfi. The problem is there are sometimes
items in the olfi collection that are not olmi's - e.g. ReportItems
(undeliverable messages), and encrypted messages (not sure what these are).
Normally, I can just loop like this:
For Each olmi In olfi
'match recipient address with strAddress
Set olrs = olmi.Recipients
For Each olr In olrs 'check every recipient the message was sent to
If olr.Address = strAddress Then
Debug.Print "Found matching Recipient address!"
End If
Next
Next
But if a non-olmi item is encountered, I get a Type Mismatch error. Is
there a way to test to make sure the item is an olmi before entering the For
Each loop? In pseudo code, it might look something like this:
For Each item In olfi
If item <> olmi then
GoTo Next_Item
Else
Set olrs = olmi.Recipients
For Each olr In olrs 'check every recipient the message was sent
to
If olr.Address = strAddress Then
Debug.Print "Found matching Recipient address!"
End If
Next
End if
Next_Item:
Next
Other suggestions?
Thanks in advance.