Deleting completed tasks from Outlook:   Return to List

Private Sub DeleteCompletedTasks()
Dim MyNS As NameSpace
Dim objItem As Object
Dim objOutlook As New Outlook.Application
Dim TaskFolder As MAPIFolder
Set MyNS = objOutlook.GetNamespace("MAPI")
Set TaskFolder = MyNS.GetDefaultFolder(olFolderTasks)
For Each objItem In TaskFolder.Items
    If objItem.Class = 48 Then ' 48 is the class for Task
        If objItem.Complete = True Then
            objItem.Delete
        End If
    End If
Next
End Sub
' Code snippet contributed by Matt G. Dekok



Note to Webmaster