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

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.
 
K

Ken Slovak - [MVP - Outlook]

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?
 
R

Russ

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.
 
K

Ken Slovak - [MVP - Outlook]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top