posted on Friday October 3, 2008 - 4:59 pm (1 month, 2 weeks ago)
tags , , ,

Microsoft Outlook can be a great collaborative program, but sometimes it seems to lack features that you think would be no-brainers. For instance, there is no easy way (that I can find) to create categories globally for all users. Obviously, you wouldn’t want to force users into using categories but in some instances it can be useful to have everyone’s “meeting” category with the same name and (probably more importantly) colour which appears in the calendar.

There are two ways to give everyone in a work group the same categories. The first is to set them up on one copy of Outlook, and export the registry keys. These keys are imported for all users. The problem here is that the keys will overwrite any other customisations.

The second way is to use the Windows Scripting Host to connect to a local instance of Outlook and create the categories. Let’s walk through how we’ll do this. Note that this has only been tested with Outlook 2007, but does not require Administrative privileges to run.

First, create an Outlook object and a connection to that object’s MAPI interface:

Dim oOutlook : Set oOutlook = CreateObject("Outlook.Application")
Dim oNameSpace : Set oNameSpace = oOutlook.GetNameSpace("MAPI")

Next, use the MAPI interface to create a new category:

oNameSpace.Categories.Add "Our category", 1, 2

Where the first number is a number between 1 and 25 and the second is between 2 and 12 (more on these later). The first number denotes the category’s colour and the second denotes the shortcut key.

Pretty simple, but you probably want something more robust that you could use in a login script to ensure all users get the same categories. A robust solution should check if the category exists so you don’t tread on anyone’s toes.

Function categoryExists(categoryName)
	Set theCategories = oNameSpace.Categories
	For Each theCategory in theCategories
		If theCategory.Name = categoryName Then
			categoryExists = True
			Exit Function
		End If
	Next
	categoryExists = False
End Function

This function loops through all of the categories and returns True if the category submitted to the function exists. To use the function, we might expand our earlier line into the following:

If Not categoryExists(catName) Then
	oNameSpace.Categories.Add catName, catColour, catShortcut
	WScript.StdOut.Writeline "Added '" & catName & "' into Outlook."
Else
	WScript.StdOut.Writeline "'" & catName & "' already exists in Outlook. Not adding."
End If

Before I mentioned integrating category creation into a login script. To do this, you want to allow people to pass categories in at the command line:

catName = WScript.Arguments.Item(0)
catColour = WScript.Arguments.Item(1)
catShortcut = WScript.Arguments.Item(2)

You can view the list of colours and shortcuts on Microsoft’s MSDN site.

Putting everything together, and we have a script which you can call from the command line using the following command:

cscript /nologo addOutlookCategory.vbs "Hello World" 4 7

This will create a new category named Hello World, which has a corresponding yellow colour, and can be set by pressing CTRL-F7.

Download the entire script for yourself:

If you find this script useful, please drop me a line in the comments below.

Related Posts:

Leave a Reply

bludger.org (version 9) © 2000-2008 bludger.org. All rights reserved.
Not many animals were harmed in the making of bludger.org, but a lot were eaten. And they were delicious.
I mean, really, really nice. I especially liked the squab, he didn't put up a fight.