PDA

View Full Version : Selecting only categorized emails



MikeFranz
02-11-2013, 11:15 AM
Hi,

I'm looking to loop through all the emails in my inbox and select only those that have been categorized. For example, say I have 3 messages, the first has been categorized as "Red", the second is not categorized and the third is categorized as "Blue". I would like to write code to only select and open emails one and three.

Anyone have some advice on how to do this?

Thanks!

Mike

skatonni
02-19-2013, 07:07 PM
Sub SearchAndDisplay_Category()

Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olInbox As Outlook.MAPIFolder
Dim olItem As Object
Dim I As Long

Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olInbox = olNS.GetDefaultFolder(olFolderInbox)

For I = olInbox.items.Count To 1 Step -1

Set olItem = olInbox.items(I)

If olItem.Categories <> "" Then

olItem.Display

End If

Next I

Set olApp = Nothing
Set olNS = Nothing
Set olInbox = Nothing
Set olItem = Nothing

End Sub