Sub AssignCategoryAndMoveBasedOnSubject(Item As Outlook.MailItem)
If InStr(1, Item.Subject, "error") > 0 Then
Item.Categories = "Error"
Item.Subject = "Error:" + Item.Subject
Item.Save
Set myNameSpace = GetNamespace("MAPI")
Set myInBox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set mydestFolder = FindOrCreateFolder(myInBox, "Text")
Item.Move mydestFolder
End If
End Sub
Function FindOrCreateFolder(inputFolder As Variant, folderName As String) As Outlook.MAPIFolder
Dim curFolder As Outlook.MAPIFolder
For Each curFolder In inputFolder.Folders
If folderName = curFolder.Name Then
Set FindOrCreateFolder = curFolder
Exit Function
End If
Next curFolder
Set FindOrCreateFolder = inputFolder.Folders.Add(folderName)
End Function
more...
No comments:
Post a Comment