Creating an email with the list of tasks

Not open for further replies.


New Member
Outlook version
Outlook 2010 64 bit
Email Account
The below code is creating an email with the list of tasks, the only issue i that each row is starting with task category.
Please your kind help to modify the code , so I can see the task category and below it the tasks.

Public Sub CreatingReportFromTasks()
Dim objTask As Outlook.TaskItem
Dim objTaskFolder As Outlook.MAPIFolder
Dim objTaskItems As Outlook.Items
Dim objNS As Outlook.NameSpace

Set objNS = Application.GetNamespace("MAPI")
Set objTaskFolder = objNS.GetDefaultFolder(olFolderTasks)
Set objTaskItems = objTaskFolder.Items

Dim strBody As String

MyCategory = ""
strBody = ""
strCategory = ""

For Each objTask In objTaskItems
If objTask.Status <> olTaskComplete And (objTask.Categories = "1" Or objTask.Categories = "2" Or objTask.Categories = "3" Or objTask.Categories = "4") Then
If objTask.Categories <> MyCategory Then
MyCategory = objTask.Categories
End If
strBody = strBody & " " & MyCategory & ":" & objTask.Subject & vbNewLine ' & strbody
End If

Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
With objMsg
.To = ""
.Body = strBody

End With
Debug.Print strBody

Set objTask = Nothing
Set objTaskItems = Nothing
Set objTaskFolder = Nothing
Set objNS = Nothing
Set objMsg = Nothing
End Sub
Not open for further replies.