VBA Excel to manage Outlook cateogries

jorgeschady

New Member
Joined
Dec 3, 2007
Messages
2
Hello everybody,

First post so apologies if doing something wrong...

I am trying to manage Outlook categories for specific mails through a VBA code. The mailbox and folders are accessed correctly, but the category is only changed when I have Outlook open and the folder itself selected. Furthermore, it only changes the category for the first element, even though they might be multiple elements that should be changed...

Any ideas?

Thanks in advance for your help!

Jorge

Code:
Sub WriteCategory()

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myfolders = myNameSpace.Folders

Sheets("Resumen").Select
wwrow = 2
 
For wwrow = 2 To 65000
 
If Cells(wwrow, "C") = "" Then
Exit For
End If

Folder1 = Cells(wwrow, "H")
Folder2 = Cells(wwrow, "I")
Folder3 = Cells(wwrow, "J")
Folder4 = Cells(wwrow, "K")
Folder5 = Cells(wwrow, "L")
Sender = Cells(wwrow, "C")
Subject = Cells(wwrow, "D")
ItemDateTime = Cells(wwrow, "E")
Itemnumber = Cells(wwrow, "A")

If Folder2 = "" Then

Set myFolderLevel1 = myfolders.Item(Folder1)


myFolderLevel1.Items(Itemnumber).Categories = "Red category"
myFolderLevel1.Items(Itemnumber).Save

ElseIf Folder3 = "" Then
Set myFolderLevel1 = myfolders.Item(Folder1)
Set myFolderLevel2 = myFolderLevel1.Folders(Folder2)

myFolderLevel2.Items(Itemnumber).Categories = "Red category"
myFolderLevel2.Items(Itemnumber).Save


End If
Next wwrow

End Sub
 

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top