I was able to embed a tab into the search string by pressing Control+i when entering it but this failed to match messages on my mail server. When I examined the actual characters in the message body of the received message I found that the {TAB} character had actual been translated into six \u00A0 (unicode) characters followed by a single space character. This prevented the search string from matching. You may want to try this method first to see if it works with your emails.
As an alternate solution, you can create a "custom" rule by adding a Visual Basic for Applications macro to Outlook.
- First enable the Developer menu by going to Outlook -> Options -> Customize Ribbon and then checking off the Developer option in the Main Tabs list on the right.
- Now back on the your main Outlook view you should see a Developer menu, select it
- Click Macro Security button on the ribbon and select either "Notification for all macros" or "Enable all macros (not recommended; potentially dangerous code can run)
- Next click the Visual Basic button on the ribbon to open the Visual Basic editor
- Goto the Tools -> References and add a reference to the Microsoft VBScript Regular Expression 5.5 library
- In the Visual Basic editor, select ThisOutlookSession and paste the code listed below.
- Save your project and exit Outlook
- Reopen Outlook and send yourself a test message
You will need to edit the string contents of the RouteToFolderName and the RouteToFolderRegEx constants to match your search preferences.
The macro is saved to a file called VBAProject.OTM located in your user settings area (C:\Users\\AppData\Roaming\Microsoft\Outlook\ folder on Windows 7). You may wish to make a backup copy of this file once you have gotten the macro working to your specifications.
Option Explicit
Private WithEvents olInboxItems As Items
' This is the name of the folder you want your messages moved to
Private Const RouteToFolderName As String = "FollowUp"
' This is the regular expression that matches the text you are '
searching for. Outlook replaced a single {TAB} character with ' 6 x
\u00A0 characters and 1 x space character. Private Const
RouteToFolderRegex As String = "Changed By:\u00A0+\s+Me"
Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.Session
' Attach the the Outlook inbox to receive an event whenever an item arrives
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing End Sub
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
Dim objNS As NameSpace
Dim objMailItem As Outlook.MailItem
Dim objMailFolderId As String
Dim regex As RegExp
Dim Found As Boolean
' Check to make sure we have a mail message first
If (TypeOf Item Is Outlook.MailItem) Then
' Locate the id of the folder we want to store the message in
objMailFolderId = FindFolderByName(Application.Session.folders, Found,
RouteToFolderName)
Set objMailItem = Item
Set regex = New RegExp
regex.IgnoreCase = True ' Do a case insensitive search
regex.Global = True
regex.Pattern = RouteToFolderRegex
' Test the message body against the regular expression
If (regex.Test(objMailItem.Body)) Then
' Message body matched so move to our folder
objMailItem.Move Application.Session.GetFolderFromID(objMailFolderId)
End If
End If
End Sub
' Recursively search from the root folder for the folder that matches
"folderName" (case insensitive) Public Function FindFolderByName(ByRef
folders As Outlook.folders, ByRef Found As Boolean, ByVal folderName
As String) As String
Dim objFolder As Outlook.Folder
For Each objFolder In folders
If Found = True Then
Exit Function
End If
If LCase(objFolder.Name) = LCase(folderName) Then
FindFolderByName = objFolder.EntryID
Found = True
Exit Function
Else
If objFolder.folders.Count > 0 Then
FindFolderByName = FindFolderByName(objFolder.folders, Found, folderName)
End If
End If
Next End Function
Still looking for answer – Jules – 2012-05-10T08:18:36.063