LessThanDot Site Logo

LessThanDot

A Technical Community for IT Professionals

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Highly Rated Users

Forum
No Posts Rated

Top 50
Given
Received

Links

Wiki
Blog

Forum Statistics

Users
Members:
1884
Members Online:
2
Guests Online:
92

Total Post History
Posts:
81461
Topics:
18719

7-Day Post History
New Posts:
4
New Topics:
1
Active Topics:
2

Our newest member
manails232x

Other

FAQ
All times are UTC [ DST ]

FAQ: Add a category when you open a mail item

Please wait...

FAQ: Add a category when you open a mail item

Postby Remou on Tue Jan 05, 2010 9:20 pm

In Outlook 2010, and probably 2007, in ThisOutlookSession:

  1. Public WithEvents myOlInspectors As Outlook.Inspectors
  2. Public myInspectorsCollection As New Collection
  3.  
  4. Private Sub Application_Startup()
  5. 'Application_Startupis a built-in event and will fire at start-up
  6. 'if security levels permit. Here it is used to initialize the
  7. 'Inspectors handler
  8.     Initialize_handler
  9. End Sub
  10.  
  11. Public Sub Initialize_handler()
  12.     Set myOlInspectors = Application.Inspectors
  13. End Sub
  14.  
  15. Private Sub myOlInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
  16. 'Outlook.Inspector class represents a window that displays a single item
  17. 'such as an e-mail message, task, or appointment in the Outlook UI.
  18. If (Inspector.CurrentItem.Class = olMail) Then
  19.  
  20.     If Inspector.CurrentItem.Parent = "Inbox" Then
  21.         'The inspector will fire for new mail as well
  22.         'as existing mail items, so this example
  23.         'checks for Inbox
  24.         strCats = Inspector.CurrentItem.Categories
  25.  
  26.         If InStr(strCats, "Read") = 0 Then
  27.             If Not strCats = vbNullString Then
  28.                 strCats = strCats & ","
  29.             End If
  30.             strCats = strCats & "Read"
  31.             Inspector.CurrentItem.Categories = strCats
  32.             Inspector.CurrentItem.Save
  33.         End If
  34.     End If
  35. End If
  36. End Sub


You will need to ensure that your security levels allow macros.
Stop quoting laws to us. We carry swords.
User avatar
Remou
LTD Admin
LTD Admin
LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971
LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971
LTD Gold - Rating: 971
 
Posts: 5414
Joined: Sun Oct 14, 2007 11:26 am
Unrated