Help - can't get categories to work!

  • Thread starter Thread starter phil baxter
  • Start date Start date
P

phil baxter

Hi all,

I have cobbled together the following code which is triggered by an incoming e-mail event.

It is supposed to automatically add a category to the e-mail (which is the domain name of the sender e-mail).

The script all executes okay, and it appears to be trying to add the right category.

But no categories actually get added.

Any help gratefully received

Phil

Running Outlook 2003, exchange server.

PS. Tried this post on different forum and got no responses at all. Hopefully you lot on here are a bit better!

------------------------------------------------------------ ----

Public Sub SortByDomain(oMsg As MailItem)
'On Error Resume Next

Dim sDomain As String 'The Sender's domain
Dim oNS As Outlook.NameSpace 'My namespace
Dim oInbox As Outlook.MAPIFolder 'My Inbox
Dim oTarget As Outlook.MAPIFolder 'The domain folder



'If it's not your domain, decipher the domain.
If InStr(oMsg.SenderEmailAddress, "[my domain]") < 1 Then
sDomain = Mid(oMsg.SenderEmailAddress, InStr(oMsg.SenderEmailAddress, "@") + 1)
'Debug.Print sDomain

Else
sDomain = "[my domain]"
End If

Debug.Print sDomain

'oMsg.Categories = oMsg.Categories & "," & sDomain

Dim sSt As String

sSt = "Business"

Debug.Print sSt

AddCat oMsg, sSt

Debug.Print sSt

End Sub

Public Sub AddCat(itm As MailItem, catName As String)

arr = Split(itm.Categories, ",")
If UBound(arr) >= 0 Then
' item has categories
For I = 0 To UBound(arr)
If Trim(arr(I)) = catName Then
' category already exists on item
' no need to add it
Exit Sub
End If
Next
itm.Categories = itm.Categories & "," & catName
Else
' item has no categories
itm.Categories = catName
Debug.Print catName

End If
End Sub
 
Thanks, that's perfect. I'm sure I had something similar in earlier code, but must have lost that call.

Again, thanks. This is massively helpful


JP wrote on Thu, 28 January 2010 08:3
 
Back
Top