![]() |
#2
|
||||
|
||||
![]()
This is fairly straightforward, however categories are case sensitive, so the following assumes "trim", "Trim" or "TRIM" are all intended to equal "TRIM" and so if they exist "TRIM" is not added again.
Code:
Sub Add_Category() Dim olItem As Object Dim Arr As Variant Dim i As Integer Const strCat As String = "TRIM" On Error GoTo err_Handler Set olItem = Application.ActiveExplorer.Selection.Item(1) If TypeName(olItem) = "MailItem" Then Arr = Split(olItem.Categories, ",") If UBound(Arr) >= 0 Then For i = 0 To UBound(Arr) If Trim(UCase(Arr(i))) = strCat Then Beep MsgBox "Already categorised with " & strCat GoTo lbl_Exit End If Next End If olItem.Categories = strCat & "," & olItem.Categories olItem.Save End If lbl_Exit: Set olItem = Nothing Exit Sub err_Handler: Beep MsgBox "Select a message!" Err.Clear GoTo lbl_Exit End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
snickerbart | Outlook | 4 | 04-17-2015 12:55 PM |
Create QuickStep: Save Contact with Category | ilcaa72 | Outlook | 1 | 05-20-2014 10:31 AM |
Macro to export email to text file on send depending on category | Joe Patrick | Outlook | 0 | 10-19-2012 06:20 PM |
How to create a Main category mirrored in Sub category data entry type of solution? | Geza59 | Excel | 0 | 10-19-2012 05:44 AM |