I would like a VBA code to set the category of the selected mail item to a string that I want to pass to it. It can be a function. Can anyone help out I have no clue where to start in VBA!!!
Goto VBA in OL (Alt+F11) and Insert->Module to add a new module then copy & paste the following code into this new module:
'----Code Start----
Sub SetCategory()
Dim olMail As MailItem
If Application.ActiveExplorer.Selection.Count = 1 And _
Application.ActiveExplorer.Selection.Item(1).Class = 43 Then
Set olMail = Application.ActiveExplorer.Selection.Item(1)
olMail.Categories = "MyCategory"
olMail.Save
End If
Set olMail = Nothing
End Sub
'----Code End----
Return Outlook and select an email message in the folder and then point to Tools->Macro->Macros then select SetCategory macro and click Run.
Now you can change this sub procedure to run with a parameter:
'----Code Start----
Sub SetCategory(catStr as string)
Dim olMail As MailItem
If Application.ActiveExplorer.Selection.Count = 1 And _
Application.ActiveExplorer.Selection.Item(1).Class = 43 Then
Set olMail = Application.ActiveExplorer.Selection.Item(1)
olMail.Categories = catStr
olMail.Save
End If
Set olMail = Nothing
End Sub
'----Code End----
Fantastic, thankyou works really well! That is great, what I have is engineers clicking a button now when mail comes into a public folder and it assigns it to them, all future replies say "In Progress" which is great! If I set it to complete, again using the categories, is there a way (not using message subject, to mark the rest of those mails complete, using some sort of message ID????
Actually I just tried this on a public folder and it worked fine for mail items, I have a lot of post items in there also. Is there a way of adapting this to detect a post and set the category for a post if its a post??
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.