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

jogos

guys this is actually very helful i am greatful to you this is actualy wonderful novos jogos de moto

by Unregistered Visitor on 10/28/14

diet

this is super all over guys as i was thinking of it to be really of well info and great tactis indeed 200 calorie meal plans

by Unregistered Visitor on 10/29/14

get that

Created with the specialised documents industry in purpose the 44\" schoolwide iPF825 outputs documents atlantic thing only a family of samples of the calibre of writing the imagePROGRAF module manipulate. if you need the driver printer, you can check at Canon imageprograf ipf825 Driver download Aesthetically, real slight is completely diverse from incompatible Epson dedicated danger printers; it\'s monovular bucket-and-handle communication of the PictureMate if you need the driver printer, you can check at epson picturemate pm235 driver download Naturally, it cannot stop a candela to the One\'s indulgent name and 4.7in, 1080p guide, object for a sub-£200 sound the give 500 is uncommonly glorious. Its shiny discolor plastic phrase is around off nicely by a color dirty take that surrounds the force and seamlessly encompasses the honor buttons on the right-hand urgency. if you need the gadgets info, you can check at htc desire 500 review specifications Using deain groundwork of 1 of the most favourite Mitsubishi SUV beginning referred to as GG - PHEV , the most recent procreation Pajero was present to circularise the populate runway high-powered hit - in organism if you need the last info about car automotive, you can check at Mitsubishi gg phev pajero review bilang untuk memasang iklan Adsense di diary, kita harus mendaftar adsensenya dari Blogger, tidak bisa dari youtube lagi if you need the last info update about technology, you can check at pengenalan google adsense echo kita PIXMA MG7570 picture the PIXMA bit & Photo fulfil with NFC susceptibility, which suggests users don't got to control urbane meshwork settings. Users can turn documents or... if you need more info about geophysics, you can check at Rahmat Punya Driver Printer Download

by Unregistered Visitor on 10/30/14

jackson

Should there be another persuasive post you can share next time, I’ll be surely waiting for it. available now

by Unregistered Visitor on 11/09/14

jackson

Blog commenting serviceGreat post full of useful tips! My site is fairly new and I am also having a hard time getting my readers to leave comments. Analytics shows they are coming to the site but I have a feeling “nobody wants to be first”.

by Unregistered Visitor on 11/10/14

zeeshan1

You have done a great job. I will definitely dig it and personally recommend to my friends. I am confident they will be benefited from this site. http://binary-options-reviews.com/text.php?lang=heb&id=4&sid=37

by ahmed raza on 11/11/14

Abbott

Truthfully, your object is beside. My buddy just compared this advise beside pay to write college essay besides he was satisfied. Someday, he designed hellos confess review for hellos body.

by Unregistered Visitor on 11/11/14

jack

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

by Unregistered Visitor on 11/11/14

Brigham

To mine memory, you selected to scratch an educational courier. I was so impressed whereas I discovered delivering supreme essay writing services further made an sequel there. The primary objective is because protected from false employs.

by Unregistered Visitor on 11/12/14

adaharhra

Kid Icarus is a mixture of platform games, action and shooter released in 1986. You play Pit, the angel helped by the goddess of light Palutena, to explore dungeons to bring the hand on the three sacred treasures, to hope to beat Medusa Goddess of Darkness. emulator 3ds

by Unregistered Visitor on 11/13/14

Emulatore 3DS

'The Legend of Zelda: Majora Mask' è essere rifatto per il Nintendo 3DS Nintendo ha annunciato che il suo successo N64 gioco 'The Legend of Zelda: Majora Emulatore 3DS Mask' è eccitato essendo rifatto per il portatile 3DS. Il gioco originale è stato rilasciato nel 2000 e ...

by Unregistered Visitor on 11/14/14

Cool

Wonderful, what a blog it is! This website presents valuable information to us, keep it up. rebel mouse forex trendy

by Unregistered Visitor on 11/21/14

Online education

These days education become so easy for all students in whole world due to top quality educational networks. I am glad to share something about online education, because i have some great idea to boost you education. Check rushmyessays professional writing service online and get free demos as well. Our company provides money back guarantee as well so don't think about any internet scam at all.

by Unregistered Visitor on 11/21/14

jackson

Good Post, I am a big believer in posting comments on sites to let the blog writers know that they’ve added something advantageous to the world wide web! https://www.rebelmouse.com/restoremyvisiontodayreviews

by Unregistered Visitor on 11/25/14

nice to be here

I just want to let you know that I just check out your site and I find it very interesting and informative. I am really impressed with this and I hope that more stuff like this will be given to us Fifa 15 Coins

by Unregistered Visitor on 11/27/14

rozi

I am looking for and I love to post a comment that "The content of your post is awesome" Great work! www.rebelmouse.com

by Unregistered Visitor on 11/27/14

jackson

http://antlerxreviews.com/ Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info.

by Unregistered Visitor on 11/27/14

You might comment

You might comment on the order system of the blog. You should chat it's splendid. Your blog audit would swell up your visitors. I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and technology

by Unregistered Visitor on 11/27/14

jackson

It was great to see the old printshop and everyone who works there again. I am excited to see a printing business still operating and growing, great job guys products

by Unregistered Visitor on 11/28/14

subjeasdst

Thank you for taking the time to publish this information very useful! ac installation coral gables

by Unregistered Visitor on 11/28/14

site translator

VBA is one of the two programming languages that is available for writing code on outlook. In vba we can simple applications like email marketing. Regards, site translator

by Unregistered Visitor on 11/29/14

rozi

Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites! Mats

by Unregistered Visitor on 11/30/14

Brigham

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it. https://rebelmouse.com/penguinmethodreviews

by Unregistered Visitor on 11/30/14

jack

Great post i cmust say and thanks for the information. Education is definitely a sticky subject. However, is still among dentist 33414 the leading topics of our time. I appreciate your post and look forward to more

by Unregistered Visitor on 12/01/14

software

Really excited post! Regarding the topic, I must say very fresh and innovative perception of you. case management software

by Unregistered Visitor on 12/02/14

hoparlör

Really excited post! Regarding the topic, I must say very fresh and innovative perception of you. Satılık hoparlör

by Unregistered Visitor on 12/02/14

precise

Thank you so much for the post you do. I like your post and all you share with us is up to date and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. precise security

by Unregistered Visitor on 12/02/14

not

Thank you so much for the post you do. I like your post and all you share with us is up to date and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. why not find out more

by Unregistered Visitor on 12/02/14

development

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information .. tips on muscle development

by Unregistered Visitor on 12/02/14

good

There are many things to understand about a solar array beyond the panels. While panels are the pretty face of your system, we all know looks can only take us so far! The inverter, in this case, is the brains. smartgrideducation.org

by Unregistered Visitor on 12/04/14

good

Education is extremely important in today's society, but how exactly do we know the degree of education to which we can say that it is of the highest quality? It can be difficult for us to determine, especially when we are talking about our children and the kind of education we want them to have. highqualityeducation.org

by Unregistered Visitor on 12/04/14

good

That big mistake if we have opinion that education is source of business. Education is for all. The people need education for build themselves for future aspiration. educationav.net

by Unregistered Visitor on 12/04/14

rozi

Three are usually cheap Ralph Lauren available for sale each and every time you wish to buy. They're produced by the very best degree developers who will be distinguished for your polo dress creating. You'll find polo Ron Lauren inside exclusive array which include particular classes for men, women.πανινα παπουτσια

by Unregistered Visitor on 12/04/14

jackson

examineramino acid blend Hey – great blog, just looking around some blogs, seems a really nice platform you are using. I’m currently using WordPress for a few of my blogs but looking to change one of them over to a platform similar to yours as a trial run. Anything in particular you would recommend about it?

by Unregistered Visitor on 12/06/14

jackson

Great, This specific net webpage is seriously thrilling and enjoyment to learn. I’m an enormous fan from the subjects mentioned. talk to turn her on

by Unregistered Visitor on 12/06/14

jackson

Hey – fantastic blog, impartial looking near several blogs, appears a truly pleasant pallet you are wearing. I’m currently wearing WordPress for a limited of my blogs however looking to amend digit of them atop to a podium analogous to yours as a hardship score. Anything in individual you would suggest about it? Buy Laptop Sleeves Online

by Unregistered Visitor on 12/06/14

adhsfhs

Dans les deux jeux, vous devez penser à des façons dans lequel vous pouvez placer vos murs afin que les troupes d'attaque ne auront pas une chance de briser. Parfois, il arrive à la question de savoir si de demander l'aide de la défense aérienne ou mettre à niveau les camps de l'armée. Vous êtes censé faire le tour de ces questions et de les faire correctement, ou bien, vous allez échouer. Ce sont les choses qui font de ces deux jeux intéressant. clash of clans hack

by Unregistered Visitor on 12/10/14

afwafw3233

clash of clans triche gemmes Nous avons quelques Clash plus de rupture de Clans nouvelles pour vous apporter aujourd'hui. Supercell vient de confirmer que le prochain Clash of Clans vacances 2014 mise à jour comprendra nouvelle Niveau 7 Giants pour Town Hall 10. Les joueurs ont été demandent depuis des semaines et maintenant nous sommes très heureux de voir que Supercell est une fois de plus fait les fans heureux en répondant à leurs exigences.

by Unregistered Visitor on 12/10/14

rozi

Once I thought about things like: why such information is for free here? Because when you write a book then at least on selling a book you get a percentage. Thank you and good luck on informing people more about it…Javier

by Unregistered Visitor on 12/11/14

rozi

Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well i really get amazed to read this. Its really good.Unimat

by Unregistered Visitor on 12/11/14

rozi

I most likely appreciating each and every bit of it. It is an incredible site and decent impart. I need to much obliged. Great employment! You all do an incredible blog, and have some extraordinary substance. Keep doing awesome.used cars houston bad credit

by Unregistered Visitor on 12/13/14

rozi

I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.luxury cars

by Unregistered Visitor on 12/13/14

rozi

This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the good work. I have been meaning to write something like this on my website and you have given me an idea.buy used cars

by Unregistered Visitor on 12/13/14

rozi

It has fully emerged to crown Singapore's southern shores and undoubtedly placed her on the global map of residential landmarks. I still scored the more points than I ever have in a season for GS. I think you would be hard pressed to find somebody with the same consistency I have had over the years so I am happy with that.buy here pay here

by Unregistered Visitor on 12/13/14

rozi

Your blogs further more each else volume is so entertaining further serviceable It appoints me befall retreat encore. I will instantly grab your rss feed to stay informed of any updates.coffee cake houston

by Unregistered Visitor on 12/13/14

rozi

Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also.mens celebrity imitation suits

by Unregistered Visitor on 12/13/14

RE

I believe this can be amidst the foremost crucial data on behalf of me. and that i am pleased reading your item. although need to remark on couple of general things, the web site vogue is good, the items is de facto pleasant prestamos rapidos online

by Unregistered Visitor on 12/13/14

rozi

Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!https://rebelmouse.com/

by Unregistered Visitor on 12/13/14

rozi

I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you! Watch this

by Unregistered Visitor on 12/13/14

jackson

mydebtconsolidationplan.com You are allowed to post names, but not links, unless they are approved and on topic.

by Unregistered Visitor on 12/14/14

rozi

Two full thumbs up for this magneficent article of yours. I've really enjoyed reading this article today and I think this might be one of the best article that I've read yet. Please, keep this work going on in the same quality.http://www.volvocars-partner.pl/euroservice/CzesciIAkcesoria/Strony/default.aspx

by Unregistered Visitor on 12/14/14

rozi

I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.sałatki na święta bożego narodzenia

by Unregistered Visitor on 12/14/14

rozi

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.http://www.kuchniaplus.pl/przepisy/przepisy-kulinarne-kuchni-plus/pierniczki-swiateczne_4010.html

by Unregistered Visitor on 12/14/14

rozi

It's really nice and meanful. it's really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull information.przepisy bożonarodzeniowe

by Unregistered Visitor on 12/14/14

rozi

Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. potrawy na boże narodzenie

by Unregistered Visitor on 12/14/14

How about sending a happy

How about sending a happy new year sms 2015 to convey happy new year 2015 your new year good wishes as message is a reminder to convey that the person is in your thoughts. New year is a festival which is celebrated worldwide all over the country with lot of joy happy new year 2015 and happiness. happy new year 2015 As we all know that after few days we all will be celebrating one of the most important and a huge event that is New Year with full of happiness and joy. happy new year In many countries this event gets celebrated on 1st January. happy new year 2015

by Unregistered Visitor on 12/14/14

rozi

Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!www.assistance-bancaire.com

by Unregistered Visitor on 12/15/14

rozi

411.ca is a Canadian owned and operated online directory that does what few other online search directories do – focus solely on helping Canadians find people and businesses in their neighborhood. 411.ca advertising

by Unregistered Visitor on 12/15/14

rozi

Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. the magic of making up pdf reviews

by Unregistered Visitor on 12/15/14

rozi

It has fully emerged to crown Singapore's southern shores and undoubtedly placed her on the global map of residential landmarks. I still scored the more points than I ever have in a season for GS. I think you would be hard pressed to find somebody with the same consistency I have had over the years so I am happy with that.trouver un associé

by Unregistered Visitor on 12/16/14

all payday lenders

This happens when the original thesis is during this process molded into a compromise.all payday lenders

by Unregistered Visitor on 12/19/14

Add comment