How to categorize emails in outlook automatically
If ShowDebug Then Debug.Print "Searching for '" & topic & "' in " & PersonalFoldersScopeĪutoLabel_Search SearchObject.Tag, PersonalFoldersScope, topicĮlseIf SearchObject.Scope = PersonalFoldersScope Then PersonalFoldersScope = "'\\Personal Folders'" ' Will only end up here if email was not categorizedĭim InboxScope As String, ArchiveScope As String, PersonalFoldersScope As StringĪrchiveScope = "'" & Outlook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Archive").FolderPath & "'" If ShowDebug Then Debug.Print "'" & topic & "' has been categorized: " & Item.Categories Item.Categories = removeSpecialCategories((i).Categories) Set Item = Application.GetNamespace("MAPI").GetItemFromID(SearchObject.Tag) If ShowDebug Then Debug.Print & " result(s) in " & SearchObject.Scope & " for '" & topic & "'" Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search)ĭim Item As Outlook.MailItem, i As Integer, topic As String Set sch = Application.AdvancedSearch(strScope, strFilter, Tag:=ID) StrFilter = "urn:schemas:mailheader:thread-topic like '" & Replace(topic, "'", "''") & "'" StrFilter = "urn:schemas:mailheader:thread-topic = ''" Private Sub AutoLabel_Search(ID As String, strScope As String, topic As String)
#How to categorize emails in outlook automatically archive
' Archive and Personal Folders are searched next (see SearchComplete sub) If ShowDebug Then Debug.Print "Searching for '" & topic & "' in " & strScopeĪutoLabel_Search Item.EntryID, strScope, topic ' Clear categories before searching, don't save in case nothing found If topic = "" Then topic = Item.ConversationTopic Public Sub AutoLabel(Item As Outlook.MailItem, Optional ByVal topic As String) If ShowDebug Then Debug.Print "'" & Item.ConversationTopic & "' has already been categorized: " & Item.Categories ' Don't overwrite stuff with labels already Private Sub myInbox_ItemAdd(ByVal Item As Object) ' Automatically label mail based on old labels Private Sub Application_MAPILogonComplete() This allows sorting the same email into multiple categories and still easily finding it in that search folder, sort of like GMail. This macro works best when all important emails to go the 'Personal Folders' top level folder and 'virtual folders' are created via Outlook Search Folders. It also tries to be a bit clever and look for old subjects such as "new subject RE: old subject" and label based on those. The macro will run on outlook launch and start tracking items as they are received. Looks for previously categorized emails first in the inbox, then in an inbox folder named 'Archive', then in a separate OST named 'Personal Folders'.