Outlook 2007 vba,categories RRS feed

  • Question

  • Is there a way to have a macro run every time a message is received checking if the subject matches a message already in the inbox or another box named "Complete"? If it does match, copy the category color from the old message to the new message.
    Thursday, June 20, 2013 8:43 PM

All replies

  • You can write a macro like that and have it called either from a rule, or from a handler for an event such as NewMailEx(), which fires when new mails are delivered.

    Ken Slovak MVP - Outlook

    Friday, June 21, 2013 2:24 PM
  • I am experienced in excel vba, but new to outlook vba. What coding could I use?
    Friday, June 21, 2013 4:35 PM
  • See for information and a sample for NewMailEx(). It even shows how to get the subject of the new mail item.

    This example shows how to get the Items in the Contacts folder:

    Change the constant used for Contacts (olFolderContacts) to olFolderInbox to get the Inbox.

    As far as category color, use the NameSpace.Categories collection to get all the existing color categories. You can add to the collection using Categories.Add() if needed. You can then assign a category to the item by Name.

    Ken Slovak MVP - Outlook

    Friday, June 21, 2013 5:25 PM
  • How do you find an email by subject, and how can you check if it has a category applied to it?
    Friday, June 21, 2013 10:00 PM
  • I am completely new to outlook vba. How can you search in the inbox for a subject and check the category assigned to it?
    Thursday, July 11, 2013 2:55 PM
  • In the Outlook VBA project open the Object Browser and select Items in the left pane and the Find or Restrict method in the right pane. Click F1 and look in the help for examples of how to use both methods to find one or more items with a certain property value, for example "[Subject]".

    Each item has a Categories property that you can examine.

    The Object Browser is your best friend. It lists all objects, collections, methods, properties and events. Usually each help entry for the Object Browser has a VBA code sample.

    Ken Slovak MVP - Outlook

    Thursday, July 11, 2013 3:02 PM
  • I had success adding a category to a new email. My issue now is when the new email arrives, I need it to search for the subject of that new email in the inbox and check if that email has a category assigned to it.
    Friday, July 19, 2013 7:46 PM
  • Read my previous reply. The object browser help for Find or Restrict shows how to search items in a folder, then you just check the Categories property of the items you find.

    Ken Slovak MVP - Outlook

    Friday, July 19, 2013 8:08 PM