Announcement

Collapse
No announcement yet.

Creating an email from the list of tasks

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating an email from the list of tasks



    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.


    Code:
    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
    Next
    
    Dim objMsg As MailItem
    Set objMsg = Application.CreateItem(olMailItem)
    With objMsg
    .To = ""
    .Body = strBody
    '.Display
    
    End With
    Debug.Print strBody
    
    Set objTask = Nothing
    Set objTaskItems = Nothing
    Set objTaskFolder = Nothing
    Set objNS = Nothing
    Set objMsg = Nothing
    End Sub
Working...
X