Clear one category when another is chosen

realmofconfusion

New Member
Outlook version
Outlook 365 64 bit
Email Account
Office 365 Exchange
Hi folks, hope you can help. I'm very familiar with Excel VBA, but never done anything in Outlook before.

What I'm after, assuming it's possible, is a macro that will clear a specific category whenever another, different, category is set. Specifically, if I have an email that's been set to category blue ("TO ACTION"), then if I apply category yellow ("COMPLETED"), then I want the existing "TO ACTION" category to clear, so that only the "COMPLETED" category/status is set.

Setting the categories manually just applies both, so what I'm after is a way to clear one when the other is set. I don't want to press a button to make the changes, I'm after a way to automatically remove the "TO ACTION" category whenever the "COMPLETED" category is set.

Most of what I've learned of Excel VBA is through a combination of trial and error and using the macro recorder to get an idea of the code, but Outlook doesn't have a macro recorder, so I'm at a loss as to what specific commands are required.

Any assistance will be greatly appreciated.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I assume you want it automated... this macro should work - the category version is at the end. It adds a category -

This version of the itemchange macro should be the code you need to remove the existing categories and keep the last one added

Code:
Private Sub OlItems_ItemChange(ByVal Item As Object)
Dim arrCat As Variant

' if there are categories you don't want this to apply to 
If Item.Categories = "Sent" Then Exit Sub

arrCat = Split(Item.Categories, ",")
    If UBound(arrCat) >= 0 Then
      strCat = Trim(arrCat(0))
      Debug.Print strCat
    Else
      Exit Sub
    End If

    With Item
     .Categories = strCat
     .Save
    End With

End Sub

If you will be using a limited # of replacement categories, you could use macro to assign the category - select an item, run the macro. Using .categories = "my category" will replace existing categories. This works on open or selected items.

Code:
Public Sub SetCat()
Dim objMsg As Object

' GetCurrent Item function is at http://slipstick.me/e8mio
Set objMsg = GetCurrentItem()

With objMsg
.categories = "my category"
    .Save
End With

Set objMsg = Nothing
End Sub

To keep the code short and use with multiple categories, set the category name and pass it to the main macro. Add buttons to the ribbon for the public subs.

Code:
dim strCat as String

Public Sub CatRed()
strCat = "Red"
SetCat
End Sub

Public Sub CatBlue()
strCat = "Blue"
SetCat
End Sub

Private Sub SetCat()
Dim objMsg As Object
' GetCurrent Item function is at http://slipstick.me/e8mio
Set objMsg = GetCurrentItem()

With objMsg
.categories = strCat
    .Save
End With

Set objMsg = Nothing
End Sub
 
Similar threads
Thread starter Title Forum Replies Date
C-S-R How to clear an Outlook (To Do) Task Flag? Using Outlook 8
B Clear Offline Items (Mail Folder) via VBA Outlook VBA and Custom Forms 1
mikolajek Macro to clear flags? Using Outlook 2
L Clear Offline (Task) Items using VBA Outlook VBA and Custom Forms 0
M Clear custom date field after recurrence Outlook VBA and Custom Forms 0
Diane Poremsky Clear Outlook's Most Recently Used lists Using Outlook 0
K clear categories on Exchange 2003 & Outlook 2003 Exchange Server Administration 1
Z Cannot change Clear Day (stationery) theme font Using Outlook 3
B Is there a way to make a clear button on custom form? Outlook VBA and Custom Forms 1
D Code to clear certain fields in Outlook Form Outlook VBA and Custom Forms 7
S BCM Not Able to Complete Task - Window won't Clear BCM (Business Contact Manager) 1
D How to clear categories Outlook VBA and Custom Forms 2
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
R Auto Assign Category colours to Incoming Emails based on whom the email is addressed Outlook VBA and Custom Forms 3
A Unflag Inbox and Flag Inbox with Orange Category After Item is send Outlook VBA and Custom Forms 3
bhamberg Contacts in a category Outlook VBA and Custom Forms 11
K Custom Category Colors Using Outlook 2
4 Macro to set the category of Deleted Item? Outlook VBA and Custom Forms 2
K Update Appointment category when changed in Excel Using Outlook 3
soadfan assign category (VBA) Using Outlook 7
J Automatic color category according to variable domains Outlook VBA and Custom Forms 4
Diane Poremsky Category Color doesn't Display in Inbox Using Outlook 0
Wolfkc Unwanted Category "Starred in Android" Using Outlook 6
M receive mail when appointment category changes and create task from appointment Outlook VBA and Custom Forms 0
N VBA Outlook reference to Excel and assigning category Outlook VBA and Custom Forms 13
A recover contact category assignments Using Outlook 4
A Grouping emails using "From" causes a None Category Using Outlook 5
J Outlook Rules not show Master Category List Using Outlook.com accounts in Outlook 4
William getting custom form to load category colors Outlook VBA and Custom Forms 4
Diane Poremsky Categorize Messages using Contact Category Using Outlook 0
T Macro to find contacts by category and copy them to another folder Outlook VBA and Custom Forms 15
bifjamod Saving sent email to specific folder based on category with wildcard Outlook VBA and Custom Forms 1
K Outlook 2010 - Set the category based on category of other emails in same conversatio Using Outlook 20
A How are you handling Outlook.com category issue and syncing Using Outlook.com accounts in Outlook 2
T default category Outlook VBA and Custom Forms 2
R click to toggle quick click category reasigns to where ? Using Outlook 2
L Change Category in a Task via macro Using Outlook 8
K Help! I selected every contact and mistakenly made them all the same category Using Outlook 1
R Filter Views by Category Using Outlook 2
S categories are being cut off after selecting from category pop up form Using Outlook 3
D Search on Category in Outlook 2013 Using Outlook 1
R Any idea why my category colours aren't showing in my calendar? Using Outlook 0
M Searching for categories not in the master category list Using Outlook 3
L Category List Using Outlook 43
F Export Outlook contacts by One Category Using Outlook 1
M Cannot change category in inbox; Can change it in popup Using Outlook 0
R Restore Master Category List Outlook 2013 Using Outlook 7
D Macro to export mail data based on assigned category Using Outlook 3
C Custom form with custom colour category visible to all users in public folders Using Outlook 1
J Contacts: Assigning followup date by category Using Outlook 2

Similar threads

Top