VBOffice

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: 25.251  | #141
◀ Previous sample Next sample ▶
SAM SAM
Determine the "identity" of your emails. Set with SAM the sender and the folder folder for sent items with the help of rules.

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
  '...
  'done
  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
  Next
End Sub
Category-Manager Category-Manager
With Category-Manager you can group your Outlook categories, share them with other users, filter a folder by category, automatically categorize new emails, and more. You can use the Addin even for IMAP.
email  Send a message