Outlook 2007 Programming Bug – Adding Categories
The Outlook 2007 Object Model introduced the ability to access the Master Categories list via code for the first time. In prior versions of Outlook, this list was stored in the registry but the architecture was changed to store these entries in your mail profile. This is very handy for Exchange solutions as the Master Categories list would then be accessible for the same user using the same profile on a different computer.
However, I discovered a bug while building an add-in for a client which retrieves new categories via a web service. I found that the categories I was adding were not present after the profile was closed and reopened. Here’s a simple VBA code sample that illustrates how to properly add a category to the Master Categories list using the Microsoft.Office.Interop.Outlook.Categories collection obtained from the Microsoft.Office.Interop.Outlook.NameSpace object:
Sub TestCategories()
Dim objCats As Categories
Dim objNewCat As Category
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set objCats = objNS.Categories
Set objNewCat = objCats.Add("TESTCATEGORY1", OlCategoryColor.olCategoryColorDarkOlive)
End Sub
If you run this as a macro, then restart Outlook, you’ll notice that “TESTCATEGORY1” is not in the Master Categories list. It should be!
This bug has been submitted to the Outlook Program Managers responsible for development and verified in Outlook 2007 SP2. I haven’t tested against previous versions, but I assume the bug still exists. This bug does NOT occur in Outlook 2010.
UPDATE:
The Outlook team has confirmed that this is a known issue with Outlook 2007 SP2 only, for both .pst based and Exchange profiles.
Also, fellow Outlook MVP Ken Slovak has dug deeper and found out exactly why this isn’t working:
If you add a new Category using the UI it gets added to the hidden "IPM.Configuration.CategoryList" item in the Calendar folder. If you use code to do that it isn't added to the hidden item, therefore the new Category doesn't persist…The PR_ROAMING_XMLSTREAM PT_BINARY property (0x7C080102) isn't updated when using code as it is when performing the customization in the UI.
Good work Ken!
UPDATE 2 (14/08/2009):
A hotfix for this bug was already released on June 30th, so this isn’t that new after all:
Description of the Outlook 2007 hotfix package (Outlook.msp): June 30, 2009:
http://support.microsoft.com/default.aspx/kb/970944/en