Setting Outlook Categories with VBA
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
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
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
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".
by Unregistered Visitor on 06/17/11
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
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
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
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
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