A
andy tomic
Hi all
Getting a little stuck on my outbound rules / vba code. I currently
run an excellent addin called TAGLOCITY which tags emails with
categories. What I am trying to do PREFIX the mail subject based on
the category. NOTE: The taglocity addin triggers a category request
AFTER the item.send action.
for example;
I have a category "100 Love St" (this is my project name)
I have a color for all PROJECTS -- construction project are DARKGREEN
When I send the mail I want the addin to check the subject for a ":"
Then if there is no ":", prefix with "Job:" and the category.
I have the code for this and it works fine if i manually trigger the
vba code. I have a rule to hold the email in outbox for 1minute to
give the program time to modify and for me to go in and cancel the send
. My question is how can I trigger the code to work AFTER the
item.send command and there after the TAGLOCITY addin has had a chance
to add in the category.
code below:
Sub PrefixMailItemInOutbox()
Dim oNS As Outlook.NameSpace
Dim oFld As Outlook.Folder
Dim oItems As Outlook.Items
Dim oItem As Object
Dim Item As Outlook.MailItem
On Error GoTo OL_Error
Set oNS = Application.GetNamespace("MAPI")
Set oFld = oNS.GetDefaultFolder(olFolderOutbox)
Set oItems = oFld.Items
'Set objItem = GetCurrentItem()
StoreID = oFld.StoreID
For Each oItem In oItems
If InStr(1, oItem.Subject, ":", vbTextCompare) = 0 Then
If Len(oItem.Categories) > 0 Then
Set objItem = oNS.GetItemFromID(oItem.EntryID, StoreID)
For Each objCategory In oNS.Categories
If InStr(1, objItem.Categories, objCategory.Name, vbTextCompare)
Case OlCategoryColor.olCategoryColorDarkRed
objItem.Subject = "Roofing:" & objCategory.Name & " - "
& objItem.Subject
objItem.Save
Case OlCategoryColor.olCategoryColorBlack
objItem.Subject = "Carpentry:" & objCategory.Name & " -
" & objItem.Subject
objItem.Save
Case OlCategoryColor.olCategoryColorDarkGreen
objItem.Subject = "Job:" & objCategory.Name & " - " &
objItem.Subject
objItem.Save
End Select
End If
Next
End If
objItem.Send
'Set objItem = Nothing
End If
Next
Exit Sub
OL_Error:
MsgBox Err.Description
Err.Clear
End Sub
Thanks in advance
Andy
Getting a little stuck on my outbound rules / vba code. I currently
run an excellent addin called TAGLOCITY which tags emails with
categories. What I am trying to do PREFIX the mail subject based on
the category. NOTE: The taglocity addin triggers a category request
AFTER the item.send action.
for example;
I have a category "100 Love St" (this is my project name)
I have a color for all PROJECTS -- construction project are DARKGREEN
When I send the mail I want the addin to check the subject for a ":"
Then if there is no ":", prefix with "Job:" and the category.
I have the code for this and it works fine if i manually trigger the
vba code. I have a rule to hold the email in outbox for 1minute to
give the program time to modify and for me to go in and cancel the send
item.send command and there after the TAGLOCITY addin has had a chance
to add in the category.
code below:
Sub PrefixMailItemInOutbox()
Dim oNS As Outlook.NameSpace
Dim oFld As Outlook.Folder
Dim oItems As Outlook.Items
Dim oItem As Object
Dim Item As Outlook.MailItem
On Error GoTo OL_Error
Set oNS = Application.GetNamespace("MAPI")
Set oFld = oNS.GetDefaultFolder(olFolderOutbox)
Set oItems = oFld.Items
'Set objItem = GetCurrentItem()
StoreID = oFld.StoreID
For Each oItem In oItems
If InStr(1, oItem.Subject, ":", vbTextCompare) = 0 Then
If Len(oItem.Categories) > 0 Then
Set objItem = oNS.GetItemFromID(oItem.EntryID, StoreID)
For Each objCategory In oNS.Categories
If InStr(1, objItem.Categories, objCategory.Name, vbTextCompare)
Select Case objCategory.Color0 Then
Case OlCategoryColor.olCategoryColorDarkRed
objItem.Subject = "Roofing:" & objCategory.Name & " - "
& objItem.Subject
objItem.Save
Case OlCategoryColor.olCategoryColorBlack
objItem.Subject = "Carpentry:" & objCategory.Name & " -
" & objItem.Subject
objItem.Save
Case OlCategoryColor.olCategoryColorDarkGreen
objItem.Subject = "Job:" & objCategory.Name & " - " &
objItem.Subject
objItem.Save
End Select
End If
Next
End If
objItem.Send
'Set objItem = Nothing
End If
Next
Exit Sub
OL_Error:
MsgBox Err.Description
Err.Clear
End Sub
Thanks in advance
Andy