Find Address in CC and Move the Email

This sample finds an address in the list of recipients and then moves the email.

Last modified: 2009/11/23 | Accessed: 57.049  | #79
◀ 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.

With rules you can only look for your own address in the cc field in order to move the email. With this example you can look for any string in CC. If it's found, the email will be moved into a subfolder of the inbox. In this sample the folder is named 'test'.

tip  How to add macros to Outlook
Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
  Dim Ns As Outlook.NameSpace

  Set Ns = Application.GetNamespace("MAPI")
  Set Items = Ns.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
  If TypeOf Item Is Outlook.MailItem Then
    MoveMessage Item
  End If
End Sub

Private Sub MoveMessage(Item As Outlook.MailItem)
  Dim Ns As Outlook.NameSpace
  Dim Recipients As Outlook.Recipients
  Dim Recip As Outlook.Recipient
  Dim Folder As Outlook.MAPIFolder
  Dim Find As String, FolderName As String

  Find = "info"
  FolderName = "test"

  Set Recipients = Item.Recipients
  For Each Recip In Recipients
    If Recip.Type = olCC Then
      If InStr(1, Recip.Address, Find, vbTextCompare) Then
        Set Ns = Application.GetNamespace("MAPI")
        Set Folder = Ns.GetDefaultFolder(olFolderInbox)
        Set Folder = Folder.Folders(FolderName)
        Item.Move Folder
        Exit For
      End If
    End If
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