Outlook: Marking an Item with a Category

Use the supplied Outlook VBA code to assign a message category to an Outlook item with one click.

Sue Mosher

March 28, 2004

2 Min Read
ITPro Today logo in a gray background | ITPro Today


Can I place a button in the toolbar that will assign a specific message category to an item with one click?

Sure, that's easy. Just place the code that Listing 2, page 6, shows in a regular module in Outlook Visual Basic for Applications (VBA). If you're just getting started with Outlook VBA, Outlook VBA on Demand, "Back to Basics," August 2001, InstantDoc ID 21522, explains how to set the macro security level, get into the VBA programming environment, and create your first macro. The article also explains how to add a macro as a toolbar button.

Here are a few notes about the code:

  • The MarkA and MarkB procedures both call the same MarkWithCategory procedure, but each assigns a different category to the selected item. You can make as many individual category macros like this as you need or even create a separate Categories toolbar to hold a toolbar button for each macro.

  • GetCurrentItem() is a function that returns either an item selected in a folder view or an individual open item. Thus, you can use the MarkA and MarkB procedures from either a folder or an item window. You can also reuse GetCurrentItem() in any macro that you write to work with a selected or open item.

  • The MarkWithCategory procedure always appends the new category to the existing Categories value for the item. It doesn't check whether the category is already present. I haven't experienced any problems with having a category listed twice, but you could refine the code to check the existing Categories value to see whether a category is already present before adding it.

  • The objItem.Categories = ... statement in MarkWithCategory assumes that you're in some part of the world that uses the comma as the default list separator. If you're in a country that uses the semicolon or other separator, you need to replace the comma with that separator.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like