Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set e-mail category

Status
Not open for further replies.

Leeus

Programmer
Sep 10, 2001
40
0
0
GB
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!!!
 
Hi,

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----

And call from another sub like below:

Call SetCategory("MyCategory")

I hope it helps.
Suat

Oz
 
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????

Thanks,

Lee
 
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??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top