Office 2007, Outlook2007, Macros/VBA: How to work better with Categories

As a "technical evangelist", I should say that I spend most of my time within Visual Studio. Reality is that I spend most of my time within Outlook, which has become my main source of information - Through emails, mailing lists, and rss feeds.

To survive in my jungle of information items, I heavily use Categories. This post explains how I have implemented a few little macros that allow me to have a menu bar with my most-used categories, at 1-single-click distance of any actions. It looks like this:


(You can apply your category selection to multiple items)

Step 1: Create the necessary macros

  1. In Outlook, click Tools / Macro / Visual Basic Editor

  2. Create a Module

  3. Copy and adapt for your needs the following code: 

  4. Sub UrgentAndImportant()
      Call updateCategoryMain("01 Emails - Urgent+Important")
    End Sub

    Function updateCategoryMain(cat As String)

        Dim myOlExp As Outlook.Explorer
        Dim myOlSel As Outlook.Selection
        Set myOlExp = Application.ActiveExplorer
        Set myOlSel = myOlExp.Selection
        Dim i As Integer
        For i = 1 To myOlSel.Count
            Call updateCategory(myOlSel(i), cat)
        Next i

    End Function

    Function updateCategory(mi As Object, cat As String)

        Dim pos As Integer
        pos = InStr(1, mi.Categories, cat, vbTextCompare)
        If pos > 0 Then
            a = Left(mi.Categories, pos - 1)
            b = Right(mi.Categories, Len(mi.Categories) - pos - Len(cat) + 1)
            res = a & b
            mi.Categories = res
            mi.Categories = mi.Categories + "," + cat
        End If

    End Function

updateCategoryMain and updateCategory are used to set the categories. You can keep them as they are (or make them more robust, if required).

urgentAndImportant is the name that I have chosen for the macro that sets the category of an item to "01 Emails - Urgent+Important". This corresponds to the name in my category list under Actions / Categories / All Categories...


Just do the same for the categories that you would like to have on your menu bar.


Step 2: Create the menu bar

In Outlook, click Tools / Customize / Toolbars Tab and create your new menu bar by clicking New....

Tools-Customize-ToolbarsTab (outlook)

Under Commands select Macros and chose the macros you have defined. Drag each of them on your new menu bar.

Right-clicking on the new buttons, you will be able to change them upon your wishes. What I did was

  • Changing the name

  • Copying my icons with Paste Button Image

    • Here, I have used a small trick. Within Powerpoint, I have created a square and applied the colors of my choice. Then with the Snipping Tool, I have copied a square of color, which I have then pasted with the above command. It was surely better than working with the icon editor...

Tools-Customize-(Make Menu)

Step 3: Sign the macros

Last step, is to sign your macros. Outlook per default disables the execution of Macros - For security reasons.


To allow the execution of your macros, you have to sign them and let Outlook know that he can trust your signature.

This is what I have done:

  1. I have created my own certificate via the Digital Certificates for VBA projects tool. You can find it under Start / All Programs / Microsoft Office / Microsoft Office Tools.

  2. Within the Visual Basic Editor, sign your macros with this new certificate (Tools / Digital Signature).

Tools-Digital Signature (within VB Editor)

The first time you run your macros, tell the system to always trust your signature.

Your are done! Enjoy your new menu bar!

Skip to main content