marking an incoming message when I am not in the 'To' or the 'Cc'

  • Thread starter Thread starter Russ
  • Start date Start date
R

Russ

I have written a lot of VBA code in excel but not in Outlook.

I would like to mark incoming messages that I recieve with a color if I am
not in the 'To' list or the 'Cc' list (which means I got the message as a
'Bcc'). I looked over using rules but they fall just short.
 
Do you mean mark it with a colored flag or with a colored format in the
folder view? There's no code access to setting up an autoformat for a view
that will color specific items.

What version of Outlook?
 
Yes i should have been more explicit. I just want a colored flag next to the
email in the inbox list. I am running outlook 2007.
 
Put this code in the ThisOutlookSession class module. It uses the new
flagging for Outlook 2007 and will only run in Outlook 2007. It will run
when new items come into the Inbox.

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim IDs() As String
Dim oNS As Outlook.NameSpace
Dim obj As Object
Dim oMail As Outlook.MailItem
Dim i As Long

Set oNS = Application.GetNamespace("MAPI")
IDs = Split(EntryIDCollection, ",")
For i = LBound(IDs) To UBound(IDs)
Set obj = oNS.GetItemFromID(IDs(i))
If obj.Class = olMail Then
Set oMail = obj
With oMail
If ((InStr(1, .To, "Joe Foobar", vbTextCompare) = 0) _
And (InStr(1, .CC, "Joe Foobar", vbTextCompare) = 0)) Then

' can be any of the new OlMarkInterval enum members
.MarkAsTask olMarkNoDate

.FlagRequest = "Must be Bcc"

.Save
End If
End With
End If
Next
End Sub
 
Back
Top