Begin main content

Setting Outlook Categories with VBA

Posting this in a bit of a hurry. For context see the previous post How to do tagging in Outlook.

Open up the vba editor (Tools->Macro->Visual Basic Editor). Add a new module and paste the following code in (edit to suit).

Then to add the sub as a toolbar button customise the toolbar in the normal way and choose the 'Macros' category in the left pane - all your applicable macros will appear in the right pane. You can just drag it to your toolbar.

If the button seems to do nothing your outlook security settings may not be allowing macros. See Office Macro Security Settings.

Public Sub TagArchived()
    Dim objOutlook As Outlook.Application
    Dim objInspector As Outlook.Inspector

    Dim strDateTime As String

    ' Instantiate an Outlook Application object.
    Set objOutlook = CreateObject("Outlook.Application")

    ' The ActiveInspector is the currently open item.
    Set objExplorer = objOutlook.ActiveExplorer

    ' Check and see if anything is open.
If Not objExplorer Is Nothing Then' Get the current item.
Dim arySelection As Object
        Set arySelection = objExplorer.Selection
        
        For x = 1 To arySelection.Count
            strCats = arySelection.Item(x).Categories
            If Not strCats = ""Then
                strCats = strCats & ","End If
            strCats = strCats & "archived"
            arySelection.Item(x).Categories = strCats
            arySelection.Item(x).Save
        Next x
        
    Else' Show error message with only the OK button.
        MsgBox "No explorer is open", vbOKOnly
    End If' Set all objects equal to Nothing to destroy them and
' release the memory and resources they take.
    Set objOutlook = Nothing
    Set objExplorer = Nothing
End Sub

06:10 AM, 27 Oct 2006 by Mark Aufflick Permalink

Removing Tags

I use a customized toolbar to tag emails using this code. Right now if it is already tagged "archive" and you run the archive macro again it will tag it as "archive" twice. What is the code for removing the tag if it is already set? Thanks

by Unregistered Visitor on 08/25/09

same question

I have the same question. This thing is great, but it adds multiple categories to a single item. Any way to delete the old one first?

by Unregistered Visitor on 10/23/09

You are a prince among men

I am a PA for dozens of people and at this time of year I used to spend days (no exaggeration) adding all next years meetings, pay days, financial deadlines, school holidays etc to each calendar in turn. Then I discovered the outlook.hol file now I spend days reclassifying all the events so they show up in the right categories on everyone’s To Do lists! With a little bit of replication and tweaking I’ve done this thankless task in one afternoon. Thanks.

by Unregistered Visitor on 11/06/09

That's about the best rap my blog has gotten!

Glad to help :)

by Mark Aufflick on 11/12/09

To replace current categories or remove them...

If you want to replace the current category instead of removing them then delete these lines;

If Not strCats = "" Then
   strCats = strCats & ","
End If
strCats = strCats & "archived"
and replace with this;

strCats = "archived"
Of course you would replace "archived" with whatever category you please.

by Unregistered Visitor on 07/15/10

Error on recurring entries

Hello, I'm using this macro successfully for a while, but it gives me an error message on recurring meetings. Any suggestions to fix this? Thanks Pepijn

by Unregistered Visitor on 11/15/10

RE: Error on recurring meetings

I don't remember ever having a problem with recurring meetings (and goodness knows I've had a few!) Unfortunately (for you - fortunate for me :) I operate a full Apple workflow these days - not a Windows PC to be seen - so I haven't used any Outlook VBA for some time.

by Mark Aufflick on 11/16/10

Pop up once the category is been defined

Hi,

We have a mailbox where we receive multiple requests from clients and these request are being distributed among our team as a task to be worked on. Now I just wanted to know that is it possible to have a popup on users machine when admin assigns any particular mail to that user. I mean once the Category has been set for any particular mail, assignee should get a pop up on his machine saying that "Mail Item1 has been assigned to you".

Thanks,

by Unregistered Visitor on 06/17/11

smal amendment

changed it to a callable procedure and modified it a bit so that the category is not duplicated

Sub SetCat(Text)
    Dim objOutlook As Outlook.Application
    Dim objInspector As Outlook.Inspector

    Dim strDateTime As String

    ' Instantiate an Outlook Application object.
    Set objOutlook = CreateObject("Outlook.Application")

    ' The ActiveInspector is the currently open item.
    Set objExplorer = objOutlook.ActiveExplorer

    ' Check and see if anything is open.
    If Not objExplorer Is Nothing Then
        ' Get the current item.
        Dim arySelection As Object
        Set arySelection = objExplorer.Selection
        
        For x = 1 To arySelection.count
            strCats = arySelection.Item(x).Categories
            If Not strCats = "" Then
                For i = 1 To Len(strCats)
                    If Mid(strCats, i, Len(Text)) = Text Then
                        NextFor = True
                        Exit For
                    End If
                Next i
                strCats = strCats & ","
            End If
            If NextFor = True Then
                NextFor = False
                GoTo NextX
            End If
            strCats = strCats & Text
            arySelection.Item(x).Categories = strCats
            arySelection.Item(x).Save
NextX:
        Next x
        
    Else
        ' Show error message with only the OK button.
        MsgBox "No explorer is open", vbOKOnly
    End If

    ' Set all objects equal to Nothing to destroy them and
    ' release the memory and resources they take.
    Set objOutlook = Nothing
    Set objExplorer = Nothing

End Sub

by Unregistered Visitor on 06/21/11

Thanks for fixing my problem!

I've been trying to do this for ages, and I have written a macro that works for single emails, but not for multiple emails. I've found out the problem was that I was missing: email.Save That's fixed things, thanks!

by Unregistered Visitor on 07/24/11

Similar but different

Hi, I was wondering if it was possible to do a very similar procedure but a little different. There is a shared inbox where multiple emails are sent to a central email address and cced to a specific person. What would be the code to automatically categorize the email to the cced person? Thank you.

by Unregistered Visitor on 09/20/11

Taking up less space

Hi All, I slightly modified this so as to reduce the size of the code when creating multiple tags. This has to be set as a global variable Dim TagName As String Then you create the tag you want Public Sub TagArchive() TagName = "Archive" Call TagVariable End Sub Then rename the master macro as TagVariable Then you replace strCats = strCats & "archived" with strCats = strCats & TagName Then you can make multiple tags and only take up 4 lines, so you don't have to scroll though heaps of code each time you take a look.

by Unregistered Visitor on 07/26/12

Modification request.

How can this be modified so that it toggles the category on/off, taking into account that multiple categories are likely to be present already. Also, it needs to work in Outlook's 'conversation' view when I have the top-level conversation item selected (not an actual message). I will be calling it from Outlook's quick-access toolbar via a shortcut. TYVM for any support you can provide. ^_^

by Unregistered Visitor on 07/25/13

c

I merely would like to state your post is striking. Well with your agreement enable me to get hold of feed to maintain to day with forthcoming article. Thanks. Franklin Homes

by Unregistered Visitor on 02/18/15

fifa 15 monedas

I spend days reclassifying all the events so they show up in the right categories on everyone’s To Do lists! With a little bit of replication and tweaking I’ve done this thankless task in one afternoon. Thanks. fifa 15 monedas

by Unregistered Visitor on 02/18/15

fff

I was very impressed by this post, this site has always been pleasant news Thank you very much for such an interesting post, and I meet them more often then I visited this site extra large memory foam dog beds

by Unregistered Visitor on 02/18/15

reply

This is the website that I head to when I have any technical difficulty with the Outlook program. The steps to set Outlook categories with VBA are well explained on the page and were much informative. Thank you so much for sharing. specialty cheese

by Unregistered Visitor on 02/19/15

http://www.autoreisenzug.com

This is a very good post. Just wonderful. Truly, I am amazed at what informative things you've told us today. http://www.autoreisenzug.com

by Unregistered Visitor on 02/19/15

http://www.autonomyla.com

Thank you for another fantastic posting. Where else could anyone get that kind of information in such a perfect way of writing? I have a speech next week, and I was looking for more info ;) http://www.autonomyla.com

by Unregistered Visitor on 02/19/15

http://www.autoclima-u-go.com

I am very happy to read this. This is the kind of manual that needs to be given and not the random misinformation t hat's at the other blogs. Appreciate your sharing this best posting. http://www.autoclima-u-go.com

by Unregistered Visitor on 02/19/15

awfwa32

Crack Dragon age inquisition Un'altra cosa che gli utenti possono provare prima di adottare misure più estreme è quello di pulire eventuali residui rimasti dalla grande Android 5.0 aggiornamento Lollipop. Gli utenti avanzati possono andare in recupero ruotando il telefono e riaccenderlo tenendo potenza e volume, e svuotare la cache. Non cancellare i dati, in modo da cancellare l'intero smartphone e tutti i file. Pulendo la cache di solito risolve quasi tutti i problemi, ed è il prossimo passo. Dragon age inquisition crack windows 10

by Unregistered Visitor on 02/19/15

hack facebook

his was actually what I was looking for, and I am glad that I finally got here! Thanks for sharing and keep up the good work. I will recommend my friends to enter this site.hack facebook here

by Unregistered Visitor on 02/19/15

Accredited GED Online

It's in fact very complex in this busy life to listen news on Television, so I simply use internet for that reason, and take the most recent news. Accredited GED Online

by Unregistered Visitor on 02/21/15

enterprise cloud solutions

am permanently exploring online for articles that can be of assistance to me. Thank you enterprise cloud solutions

by Unregistered Visitor on 02/21/15

jadegraham

Then to add the sub as a toolbar button customise the toolbar in the normal way and choose the 'Macros' category in the left pane - all your applicable macros will appear in the right pane. You can just drag it to your toolbar. Boston newspaper

by Unregistered Visitor on 02/21/15

w

Great post, you have pointed out some excellent points, I as well believe this is a very superb website. health news

by Unregistered Visitor on 02/22/15

fff

I want you to thank for your time of this wonderful read!!! I definately enjoy every little bit of it and I have you bookmarked to check out new stuff of your blog a must read blog!!!! Security Screen Doors and Windows

by Unregistered Visitor on 02/23/15

Mens fashion blogs

Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing. Mens fashion blogs

by Unregistered Visitor on 02/23/15

sa2

If you are a beginning beekeeper you must start practicing good animal husbandry. In beekeeping you should not do anything until you completely understand the reason that you are doing it. An escape slot in inner cover is a good idea, it will aid with ventilation. Calculatoare Second Hand

by Unregistered Visitor on 02/25/15

saaw1

The joys of camping! What a great adventure in nature that is an excellent choice for a vacation with your family or by yourself. You should learn as much as you can about camping before you head out. Motocositori ferarri

by Unregistered Visitor on 02/25/15

asad2

I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page! Jucarii din lemn

by Unregistered Visitor on 02/26/15

imti

I have written a macro that works for single emails, but not for multiple emails. I've found out the problem was that I was missing: .. jaipur car rental

by Unregistered Visitor on 02/26/15

sad2

It was very useful for me. Keep sharing such ideas in the future as well. This was actually what I was looking for, and I am glad to came here! Thanks for sharing such a information with us. Creare magazin online

by Unregistered Visitor on 02/28/15

JAMS

I have perused such a variety of article of this site in which some of them were exceptionally intresting and inspiring.this article has great title with great portrayalhttp://math.fullerton.edu/?film-streaming

by Unregistered Visitor on 02/28/15

locksmith

Here at LocalMaster. Locksmith we understand the importance of your security needs and that is why we provide emergency locksmith service in Toronto around the clock for you! Whether you require a locksmith for your vehicle, a locksmith for your home or a commercial locksmith we will always have the right solution for you, every time. Locksmith Burlington

by Unregistered Visitor on 02/28/15

Internet Marketing Conference

They are all seeking to make some money with no visible results for you. With these people, you end up losing money, time, and your motivation too.Internet Marketing Conference

by Unregistered Visitor on 03/01/15

wallens

i am for the first time here. I found this board and I in finding It truly helpful & it helped me out a lot. I hope to present something back and help others such as you helped me. live news channels

by Unregistered Visitor on 03/01/15

asad

Thanks for your insight for your fantastic posting. I’m glad I have taken the time to see this. custom t shirts nyc

by Unregistered Visitor on 03/01/15

asvasgv

Here at LocalMaster. Locksmith we understand the importance of your security needs and that is why we provide emergency locksmith service in Toronto around the clock for you! Whether you require a locksmith for your vehicle, a locksmith for your home or a commercial locksmith we will always have the right solution for you, every time. Locksmith Halton

by Unregistered Visitor on 03/01/15

Some words about...

I like this blog very much, Its a really nice berth to read and incur info . wife swaping new york next door wives

by Unregistered Visitor on 03/02/15

Thanks for your best article, i love it

Allowing you to print, copy, scan and fax, the web-connected PIXMA MX926 is the ultimate addition to any home office. if you need the driver printer, you can check at Canon Pixma Mx926 Driver Download With an Automatic Document Feeder that loads up to 35 pages for fast double-sided copying, scanning and faxing if you need the driver printer, you can check at Canon Pixma Mx926 Driver Download this All-in-One Printer provides convenience and functionality alongside superior performance. if you need the driver printer, you can check at Canon Pixma Mx926 Driver Download PIXMA MX308 Standard Home Office AIO, supports ChromaLife100 Photo System if you need the driver printer, you can check at Canon Pixma Mx308 driver Download which can make photo store up to 100-year album life if you need the driver printer, you can check at Canon Pixma Mx308 driver Download It's advanced multifunctional provides Print / Scan / Copy / 33.6kbps Super G3 Fax / PictBridge direct print if you need the driver printer, you can check at Canon Pixma Mx308 driver Download A close cousin to the Canon Pixma MX522 Wireless Office All-In-One Printer$103.49 at PinnacleMicro if you need the driver printer, you can check at Canon Pixma Mx922 software Download the Canon Pixma MX922 Wireless Office All-In-One Printer$99.99 at Amazon if you need the driver printer, you can check at Canon Pixma Mx922 software Download offers all the features that makes the MX522 worth considering, plus enough extra—including better photo quality if you need the driver printer, you can check at Canon Pixma Mx922 software Download and also more suitable for sharing in a micro office

by Unregistered Visitor on 03/02/15

plus size vintage prom dresses

Very much appealing to me that why I stop here and read it. Thanks for sharing this. plus size vintage prom dresses

by Unregistered Visitor on 03/03/15

mobile home roof installation

Wonderful and awesome website I just found through searching and I am glad that I found it. mobile home roof installation

by Unregistered Visitor on 03/03/15

lacrosse showcases

After many searches I found this page and it has interesting information for me and I like it. lacrosse showcases

by Unregistered Visitor on 03/03/15

LED Concepts Lighting

Your content is especially unique and outstanding to read. Thank you for sharing with us. LED Concepts Lighting

by Unregistered Visitor on 03/03/15

Modern Finans

I wanted to post a comment to let you know that you did an appreciable job and Good work. Modern Finans

by Unregistered Visitor on 03/03/15

click here to investigate

Excellent post! I must thank you for this Excellent post! I must thank you for this informative read. click here to investigate

by Unregistered Visitor on 03/03/15

sucos para emagrecer

I have bookmarked it and I am taking a look ahead to reading new Information. Please keep up the good Information! sucos para emagrecer

by Unregistered Visitor on 03/03/15

Check This Out

Simply wanted to write down a word in order to say thanks to you for those wonderful tips. Check This Out

by Unregistered Visitor on 03/03/15

Colfax high speed internet

I will instantly grab your rss feed to stay informed of any updates. Colfax high speed internet

by Unregistered Visitor on 03/03/15

Mobile Spy App

I wish more authors of this type of content would take the time you did to research and write so well. Mobile Spy App

by Unregistered Visitor on 03/03/15

Micro Gigs

Wonderful and awesome website I just found through searching and I am glad that I found it. Micro Gigs

by Unregistered Visitor on 03/03/15

moving labor

This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck. moving labor

by Unregistered Visitor on 03/03/15

electric hot water heater

We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work. electric hot water heater

by Unregistered Visitor on 03/03/15

Renal Failure

I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us. Renal Failure

by Unregistered Visitor on 03/03/15

follow fy

The article is well-written and can be considered as an interesting one to read.follow fy

by Unregistered Visitor on 03/03/15

dripfollowers

First You got a great blog .I will be interested in more similar topics. i see you got really very useful topics , i will be always checking your blog thanks. dripfollowers

by Unregistered Visitor on 03/03/15

gold ira rollovers

Also great blog here with all of the valuable information you have. Keep up the good work you are doing here. gold ira rollovers

by Unregistered Visitor on 03/03/15

asadas

At evening, they engineer blaze boats onto competitor boats, the Mongols were evil to spike beside large leashs, thereby promoting the sweep of the discharge. proiectoare led

by Unregistered Visitor on 03/03/15

click here

Useful information shared..Iam very happy to read this article..thanks for giving us nice info.Fantastic walk-through. I appreciate this post. click here

by Unregistered Visitor on 03/03/15

wallens

Thanks for taking the time to discuss that,youtube subscribers I feel strongly about this and so really like getting to know more on this kind of field. Do you mind updating your blog post with additional insight? It should be really useful for all of us. youtube views

by Unregistered Visitor on 03/03/15

fff

I am really impressed by reading this article. Interesting post and I really like your take on the issue. I now have a clear idea on what this matter is all about You could look here

by Unregistered Visitor on 03/04/15

barbaraamsel

I don’t suppose many of websites give this kind of information. lowest deductible car insurance

by Unregistered Visitor on 03/05/15

asad

I am overwhelmed by your post with such a nice topic. Imprimante Second Hand

by Unregistered Visitor on 03/05/15

College

Most of our success in the studying process of students takes success in writing academic papers and other college written work. So when students are not sure they can do it perfectly, then they can turn to qualified services http://www.perfectessaysonline.com that specialize in writing term papers. They will do this quickly and also at a low price.

by Unregistered Visitor on 03/05/15

asd2

This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses. Apartamente ieftine Bucuresti

by Unregistered Visitor on 03/05/15

JAMS

Great Information sharing .. I am very happy to read this article .. thanks for giving us go through info.Fantastic nice. I appreciate this post. My Facebook Page

by Unregistered Visitor on 03/05/15

Add comment