Rule Assistent and Lower Cases

If you create a rule to move a new email automatically to another folder, the rules wizzard ignores upper/lower cases. This script doesn't ignore the subtle distinction.

Last modified: 2015/03/14 | Accessed: 26.225  | #141
◀ Previous sample Next sample ▶
Reporter Reporter
VBOffice Reporter is an easy to use tool for data analysis and reporting in Outlook. A single click, for instance, allows you to see the number of hours planned for meetings the next month.

Outlook autoamtically calls the ItemAdd function as soon as an item is added to the inbox. The macro then looks for a certain phrase in the subject of the email and if found, moves the email to a determined subfolder of the inbox.

The rules are set in the Application_Startup procedure: The first term, for instance, 'Test' is the one that is searched in the subject, the second term, for instance, 'Folder 1' is the name of the target folder. In this sample that must be an existing subfolder of your inbox.

tip  How to add macros to Outlook
Private WithEvents InboxItems As Outlook.Items
Private m_Rules As Variant

Sub Application_Startup()
  Dim i As Long
  i = -1: ReDim m_Rules(1000)
  i = i + 1: m_Rules(i) = Array("Test", "Ordner 1")
  i = i + 1: m_Rules(i) = Array("test", "Ordner 2")
  'more rules can follow here
  ReDim Preserve m_Rules(i)
  Set InboxItems = Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub InboxItems_ItemAdd(ByVal Item As Object)
  Dim Folder As Outlook.MAPIFolder
  Dim i As Long, Find As String
  Find = Item.Subject
  For i = 0 To UBound(m_Rules)
    If InStr(1, Find, m_Rules(i)(0), vbBinaryCompare) Then
      Set Folder = Application.Session.GetDefaultFolder(olFolderInbox)
      Set Folder = Folder.Folders(m_Rules(i)(1))
      Item.Move Folder
      Exit For
    End If
End Sub
OLKeeper OLKeeper
OLKeeper reliably prevents users from closing their Outlook window and thus possibly missing reminders or e-mails.
email  Send a message