StartDownloadsServiceSamplesWorkshopsContact DeutschEnglish
 
Samples
General
Outlook®
 
Awarded by
Microsoft since 2005:
mvp logo
VBOffice Info
Visitors1769616
Impressions6637906
Links
Imprint
Privacy Policy
Contact
E-Mail: Move completed items
Author: Michael BauerHomepage
Date: 18.01.2006Accessed: 26863
  
Description

This sample demonstrates how to move an item automatically to a subfolder of the inbox as soon as you flag it as completed.

Unfortunately, the Outlook Object Model doesn't allow to move those flagged items. A workaround is to use the CDO 1.21 library. If not yet done, you need to add a reference to it via Tools/References.

Option Explicit
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_ItemChange(ByVal Item As Object)
  MoveCompletedItem Item
End Sub

Private Sub MoveCompletedItem(Item As Object)
  Dim Ns As Outlook.NameSpace
  Dim Inbox As Outlook.MAPIFolder
  Dim Subfolder As Outlook.MAPIFolder
  Dim Mail As Outlook.MailItem
  Dim Msg As MAPI.Message
  Dim SubFolderName As String

  SubFolderName = "Test"

  If TypeOf Item Is Outlook.MailItem Then
    Set Mail = Item

    If Mail.FlagStatus = olFlagComplete Then
      Set Ns = Application.Session

      Set Inbox = Ns.GetDefaultFolder(olFolderInbox)
      Set Subfolder = Inbox.Folders(SubFolderName)

      Set Msg = GetCDOMessage(Item)
      Msg.MoveTo Subfolder.EntryID, Subfolder.StoreID
    End If
  End If
End Sub

Private Function GetCDOMessage(Item As Object) As MAPI.Message
  On Error Resume Next
  Dim Session As MAPI.Session
  Dim sEntryID As String
  Dim sStoreID As String

  sEntryID = Item.EntryID
  sStoreID = Item.Parent.StoreID
  Set Session = CreateObject("MAPI.Session")
  Session.Logon , , False, False, , True
  Set GetCDOMessage = Session.GetMessage(sEntryID, sStoreID)
End Function
 
 

ReplyAll alerts you before unintentionally replying all, or if you are a confidential BCC recipient of the ... [more]

 

Access the master category list in the blink of an eye, share your categories in a network, get a reminder service, and ... [more]

 

SAM automatically sets the sender, signature, and folder for sent items, for instance based on the recipient ... [more]

 

OLKeeper reliably prevents users from closing their Outlook window and thus possibly missing reminders or ... [more]