Search code examples
excelvbaoutlookcategoriesmailitem

Update Outlook Mail categories from Excel


I'm accessing Outlook via Excel because my enterprise Outlook VBA has been disabled. I'm specifically iterating though my Inbox and updating Mail.object categories property.

Dim objOutlook As Object
Set ObjOUtlook =CreateObject("Outlook.Application")

Dim objNSpace As object
Set ObjNSpace = objNaspace.GetDefaultFolder(olFolderInbox)

Dim myFolder As Object
Set myFolder= objNSpace.GetDefaultFolder(olFolderInbox)

Dim myItems As Outlook.Items
Set myItems = myFolder.Items

For Each objItem In myFolder.items
Dim objMail As Outlook.MailItem
set objMail = objItem

objMail.Categories = "Blue"
objMail.Save

This gives the Blue category in the picture but I want to be able update with the Orange Category formatting.

Can this be achieved through excel VBA?

enter image description here


Solution

  • Unless you have something strange going on here, you just change this line:

    objMail.Categories = "Blue"

    To

    objMail.Categories = "Orange Category"

    The name in the double quotes needs to be exactly the same as the one you have setup in Outlook - ie it's case sensitive.