Execute Code When a Task is Completed

Often certain actions should take place as soon as one task is done. This sample demonstrates the general approach.

Last modified: 2007/04/13 | Accessed: 79.086  | #52
◀ Previous sample Next sample ▶
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.

In this sample a category will be assigned to a task item as soon as it is marked completed.

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(olFolderTasks).Items
End Sub

Private Sub Items_ItemChange(ByVal Item As Object)
  On Error Resume Next
  Dim Task As Outlook.TaskItem
  Const CategoryName As String = "(Complete)"

  If TypeOf Item Is Outlook.TaskItem Then
    Set Task = Item

    If Task.Status = olTaskComplete Then
      If LCase$(Task.Categories) <> LCase$(CategoryName) Then
        Task.Categories = CategoryName
      End If
    End If
  End If
End Sub
Determine the "identity" of your emails. Set with SAM the sender and the folder folder for sent items with the help of rules.
email  Send a message