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

jassicacolin

I’d love to change the spell icons, if anyone is willing to contribute art for credit then I will change it asap. I don’t think I can get sued given that it’s for non-commercial purposes but I’m not a lawyer. The Top Tier Montana |

by Unregistered Visitor on 04/13/15

best natural erectile dysfunction cures

This program is an excellent choice for men who want a low risk, high reward solution to get rid of erectile dysfunction related performance problems by restoring blood flow to the penis for powerful, long-lasting erections. best natural erectile dysfunction cures

by Unregistered Visitor on 04/13/15

Tech Audible

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). techaudible

by Unregistered Visitor on 04/14/15

best tabletop grill 2015

This program is an excellent choice for men who want a low risk, high reward solution to get rid of erectile dysfunction related performance problems by restoring blood flow to the penis for powerful, long-lasting erections. best table top grill 2015

by Unregistered Visitor on 04/14/15

Great

I was reading some of your superior paper content on this website and I conceive this internet site is really informative ! Keep on putting up.

by Unregistered Visitor on 04/14/15

latest mobiles in pakistan

Check latest mobiles in pakistan as cell phone is becoming such a fundamental part of our way of life, buying one is a vital decision. You will find already a lot of options to select from. Which makes it more difficult would be the various prices. Despite you choose which phone model and manufacturer, you need to decide where you'll get it from. Something more important rely on this last decision.

by Unregistered Visitor on 04/15/15

asdasd

I am very enjoyed for this blog. Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy. small laptop

by Unregistered Visitor on 04/15/15

This is a good pos

This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. web directory

by jdggf dffdf on 04/15/15

I admire what you have done

I admire what you have done here. I like the part where you say you are doing this to give back but I would assume by all the comments that this is working for you as well. web directory

by jdggf dffdf on 04/15/15

Accounts

Since the establishment of Zahid Jamil & Co . Chartered Accountants in 1971 by Mr.Suleman Zahid Jamil,the firm has been committed to building wealth and security for our client by providing traditional accounting, auditing,and taxation and consulting services to closely eldbusinesses. As one of the leading national accounting, audit, tax and consulting firm in Pakistan,Zahid Jamil & Co has a history of steady growth. Corporate Laws and Secretarial services == Accounting & Book Keeping Services == Business Advisory Services

by caexperts manw on 04/17/15

dgasfhsrf

http://juegodetruco.net/emulador-3ds-emulador-nintendo-3ds/ Vale la pena teniendo en cuenta ese streaming y compartir videos es ilegal si el persona/servicio que cargue el video no tiene permiso del titular del copyright. Mientras que en el Reino Unido no acabarás en la cárcel para la transmisión de una película, usted puede obtener cartas de advertencia de su ISP informando que están infringiendo derechos de autor. Emulador 3ds

by Unregistered Visitor on 04/17/15

Information

You can't just ask customerscold sore symptoms what they want and then try to give that to them. By the time you get it built, they'll want something new.

by Unregistered Visitor on 04/17/15

Gulukar

Being the richest man in thesuperior papers cemetery doesn't matter to me. Going to bed at night saying we've done something wonderful, that's what matters to me.

by Unregistered Visitor on 04/17/15

A good blog

Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work. mattress pillow top

by Unregistered Visitor on 04/18/15

rebelmouse

On my website you'll see similar texts, write what you think. web page

by ahmed raza on 04/18/15

phoenix seo

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.phoenix seo

by Unregistered Visitor on 04/19/15

asad

I have bookmarked it and I am looking forward to reading new articles.lots of great information and inspiration, both of which I need, keep your post. sistema zcode

by Unregistered Visitor on 04/19/15

Jack Morgan

Thanks for compiling such nicest information in your blogs. Articles are very informative and hope again I’ll find more like that.hop over to this website

by Unregistered Visitor on 04/20/15

thyroid in women

I've just decided to create a blog, which I have been wanting to do for a while. Thanks for this post, it's really useful! thyroid in women

by Unregistered Visitor on 04/20/15

SMAL

Vale la pena teniendo en cuenta ese streaming y compartir videos es ilegal si el persona/servicio que cargue el video no tiene permiso del titular del copyright. Mientras que en el Reino Unido no acabarás en la cárcel para la transmisión de una película, usted puede obtener cartas de advertencia de su ISP informando que están infringiendo derechos de autor.I needed to much obliged in your time for this sublime read!! I decidedly getting a charge out of every tad bit of it and I have you bookmarked to look at new stuff you weblog post. Cipto Junaedy  Cipto Junaedy  Cipto Junaedy  Jadwal MotoGP 2015 di Trans 7  Cara Upload Video ke Youtube  Download BBM Untuk Android Versi Terbaru  Cara Membuat Email  Cara Instal Windows 7 So fortunes to run over your incredible online journal. Your online journal presents to me a lot of fun.. Good fortunes with the site. Jinpoker.com Agen Judi Poker Online dan Domino Online Indonesia Terpercaya  Cahayapoker.com Agen Judi Poker Dan Domino Uang Asli Online Terpercaya Indonesia  ituDewa.net Agen Judi Poker Domino QQ Ceme Online Indonesia • Nusantarapoker.com Agen Texas Poker Dan Domino Online Tanpa Robot Terpercaya

by Unregistered Visitor on 04/20/15

get more

This is intentional somewhat differently next maternity desert as your allocations journalières pleasure ponder how very you retain declared. get more likes on instagram free

by Unregistered Visitor on 04/21/15

screen

Pension check inside England is often a strong expression on your revenue inside England. You should acquire a baseline amount annually for you to have access to a type of pension on ones retirement living. ipad screen replacement

by Unregistered Visitor on 04/21/15

IRA limitations

You possess lifted an essential offspring..Blesss for using..I would want to study better latest transactions from this blog..preserve posting.. Roth IRA limitations

by Unregistered Visitor on 04/21/15

Merchant

This warning or heads-up should not come as a surprise as we have seen people pay less attention to precautions ad guidelines. Great work. Merchant Accounts

by Unregistered Visitor on 04/21/15

Interesting topic for a blog.

Interesting topic for a blog. I have been searching the Internet for fun and came upon your website. Fabulous post. Thanks a ton for sharing your knowledge! It is great to see that some people still put in an effort into managing their websites. I'll be sure to check back again real soon. rebelmouse

by m8r-54xi731 m8r-54xi731 on 04/21/15

stamped concrete patio

Thanks for sharing your knowledge on this particular aspect and making it easier for us.stamped concrete patio

by Unregistered Visitor on 04/21/15

rebelmouse

These things are very important, good think so - I think so too... dare uno sguardo all'interno

by ahmed raza on 04/21/15

jual hajar jahanam

pusat dan supplier penjualan hajar jahannam dimana hajar jahannam ini terdiri atas dua produk yaitu hajar jahannam cair dan hajar jahannam batu yang berfungsi untuk memuaskan istri jaminan tahan lama 3 jam di ranjang. jual hajar jahanam

by Unregistered Visitor on 04/22/15

ajams

Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. http://buildawatergarden.com/home-decoration/benefits-of-installing-triangle-shade-sails-in-the-hot-summer/

by Unregistered Visitor on 04/22/15

obat herbal tbc

TBC ialah jenis penyakit infeksi yang dikarenakan oleh bakteri Tuberculosis. Penyakit TBC ini sangat sering menyerang paru-paru walaupun pada beberapa kasus menyerang organ tubuh lain dan mampu ditularkan. Tuberkulosis ini juga termasuk salah satu penyakit tertua yang diketahui menyerang banyak orang. TB bisa menyebabkan kematian di dalam 5 tahun pertama. Betapa mengerikannya TBC, tetapi kita tak perlu kuatir, karena sekarang telah hadir Obat Tradisional Tuberkulosis amazon yang mampu menyembuhkan penyakit tersebut secara alami yaitu amazon Plus obat herbal tbc. Apakah definisi dari Kanker Prostat? Penyakit Kanker Prostat adalah suatu penyakit kanker yang berkembang biak di prostat, sebuah kelenjar dalam sistem reproduksi pria. Hal ini terjadi pada saat sel kanker prostat mengalami perpindahan dan mulai berkembang di luar kendali. Sel ini bisa menyebar secara metastasis dari prostat menuju bagian tubuh lainnya, terutama bagian tulang dan lymph node. Kanker prostat mampu menimbulkan sakit, susah pipis, disfungsi seksual dan gejala lainnya obat herbal kanker prostat. Miom merupakan istilah medis untuk tumor dinding rahim. Asal mulanya sel otot dibanding rahim, namun berubah menjadi tumor & menempel pada otot dinding rahim tersebut. Ukurannya seperti kacang polong sampai sebutir angggur, miom kenyal dan bisa bertumbuh secara cepat atau lambat, sehingga awalnya satu, lama-lama bertambah banyak obat herbal miom.

by Unregistered Visitor on 04/23/15

rebelmouse

This is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great. erfahren Sie mehr

by ahmed raza on 04/23/15

voyance tarot

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon. voyance tarot

by Unregistered Visitor on 04/23/15

Nice to be visiting your blog again,

Nice to be visiting your blog again, it has been months for me. Well this article that i’ve been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share. Judi Bola Tangkas

by jdggf dffdf on 04/24/15

This is a great inspiring ar

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. Judi Bola Tangkas

by jdggf dffdf on 04/24/15

Add comment