TaskItem Events

These events are for Outlook 2003 but should also work in Outlook 2007. For each event I included a message box so you can paste the entire code section into the ThisOutlookSession module and play around with tasks to see each one fire. Some of the events also have sample code.

To use this code, paste the following into your ThisOutlookSession module. Restart Outlook, then go to your Tasks folder in Outlook and start opening tasks, editing, saving, adding attachments to tasks, etc.

Private WithEvents objExplorer As Outlook.Explorer
Private WithEvents tsk As Outlook.TaskItem

Private Sub Application_Startup()
  Set objExplorer = Application.ActiveExplorer
End Sub

Private Sub objExplorer_SelectionChange()
  If objExplorer.CurrentFolder.DefaultItemType = olTaskItem Then
    If objExplorer.Selection.Count > 0 Then
      Set tsk = objExplorer.Selection(1)
    End If
  End If
End Sub

Private Sub tsk_AttachmentAdd(ByVal Attachment As Attachment)
  MsgBox "TaskItem attachment add event"

  Select Case UCase$(Right$(Attachment.fileName, 3))
    Case "XLS", "XLSX", "XLSM", "XLSB"
      MsgBox "you attached a spreadsheet"
    Case "DOC", "DOCX", "DOCM"
      MsgBox "you attached a document"
  End Select
End Sub

Private Sub tsk_AttachmentRead(ByVal Attachment As Attachment)
  MsgBox "TaskItem attachment read event"
End Sub

Private Sub tsk_BeforeAttachmentSave(ByVal Attachment As Attachment, Cancel As Boolean)
  MsgBox "TaskItem before attachment save event"
End Sub

Private Sub tsk_BeforeCheckNames(Cancel As Boolean)
  MsgBox "TaskItem before check names event"
End Sub

Private Sub tsk_BeforeDelete(ByVal Item As Object, Cancel As Boolean)
  MsgBox "TaskItem before delete event"

  If MsgBox("Are you sure you want to delete this item?", vbYesNo) = vbNo Then
    Cancel = True
  End If

End Sub

Private Sub tsk_Close(Cancel As Boolean)
  MsgBox "TaskItem close event"

  If MsgBox("Are you sure you want to close this item?", vbYesNo) = vbNo Then
    Cancel = True
  End If

End Sub

Private Sub tsk_CustomAction(ByVal Action As Object, ByVal Response As Object, Cancel As Boolean)
  MsgBox "TaskItem custom action event"
End Sub

Private Sub tsk_CustomPropertyChange(ByVal Name As String)
  MsgBox "TaskItem custom property change event"
End Sub

Private Sub tsk_Forward(ByVal Forward As Object, Cancel As Boolean)
  MsgBox "TaskItem forward event"
End Sub

Private Sub tsk_Open(Cancel As Boolean)
  MsgBox "TaskItem open event"
End Sub

Private Sub tsk_PropertyChange(ByVal Name As String)
  MsgBox "TaskItem property change event"
End Sub

Private Sub tsk_Read()
  MsgBox "TaskItem read event"
End Sub

Private Sub tsk_Reply(ByVal Response As Object, Cancel As Boolean)
  MsgBox "TaskItem reply event"
End Sub

Private Sub tsk_ReplyAll(ByVal Response As Object, Cancel As Boolean)
  MsgBox "TaskItem replyall event"

  If MsgBox("Are you sure you want to Reply All instead of just Reply?", vbYesNo) _
      = vbNo Then
    Cancel = True
  End If
End Sub

Private Sub tsk_Send(Cancel As Boolean)
  MsgBox "TaskItem send event"
End Sub

Private Sub tsk_Write(Cancel As Boolean)
  MsgBox "TaskItem write event"
End Sub

Site last updated: May 17, 2012

Random Data Generator