Create tasks for outlook.com and a second Tasks folder

Last reviewed on June 1, 2013

This macro code sample is the result of a discussion at Microsoft Answers. Due to recent changes, Outlook.com does not support attachments in tasks, appointments, and contacts. You can add attachments to the items in Outlook 2013, but the attachments are hidden.

My work flow –
1) Receive an email with an attachment that I have to review
2) Create task with the attachment shortcut
3) When I’m ready to work the item I can just open the task, click on the attachment and start reviewing.
Now I have to use the create task with text, then go back to find the original email to find the attachment ….

There are two ways we can address this. The first method creates a task with a link to the original message.

The second method creates a task in a local task folder (that supports attachments) and creates a copy of the task (without the attachment) in your outlook.com task folder.

Create a button on the ribbon or QAT for the macro so its easy to use.

If you have Outlook configured to set reminders on tasks with a due date, a reminder will be set. If you aren't using default reminders or want to use a different reminder, see the Set Reminder section at the end.

To create appointments instead, change each instance of TaskItem to AppointmentItem and change the field names to ones supported by appointments.

Method 1: Link to the message

A link in the body does not work with Outlook.com, due to it's lack of support for rich text bodies, so I put the link in the subject. Yes, it's ugly, but it works. You could put the link in the body, but it won't be clickable. (The code snippet at the end of this page inserts a hyperlink.)

To use this macro you need to:

  1. Set macro security to low during testing. You can sign it using selfcert later.
  2. Open VBA Editor using Alt+F11
  3. Right click on Project1 and choose Insert > Module.
  4. Paste the code into the module.
  5. Select a message, run the macro. Note: if you select more than one message, it creates a task for each message.

Sub ConvertMessagetoTask()
    Dim objTask As Outlook.TaskItem
    Dim objMail As Outlook.mailItem
    Dim strID As String
    Dim strLink, strLinkText As String

For Each objMail In Application.ActiveExplorer.Selection

    strID = objMail.EntryID
    strLink = "outlook:" & strID
    strLinkText = objMail.Subject 

Set objTask = Application.CreateItem(olTaskItem)
With objTask
    .Subject = strLinkText  & " " & strLink
    .DueDate = objMail.ReceivedTime + 3
    .StartDate = objMail.ReceivedTime + 2
    .Body = objMail.Body
    .Categories = "my category"
    .Save
End With

    Next
 
    Set objTask = Nothing
    Set objMail = Nothing
End Sub

Method 2: Create two tasks from message

This macro creates two tasks for each selected message(s). The first task includes the original message as an attachment and saves it to a local Tasks folder that supports attachments. It then creates a second task with only the message body in the task and saves it to the (default) Outlook.com folders.

In addition, the EntryID of the local task which contains the attachment is added to the Subject field (so it's clickable). This allows you to open the "attachment task" from the main task.

To use this code you need to:

  1. Set macro security to low during testing. You can sign it using selfcert later.
  2. Open VBA Editor using Alt+F11
  3. Right click on Project1 and choose Insert > Module.
  4. Paste the code below into the module.
  5. Edit the folder path for the local folder
  6. If you don't want the message body in addition to the attachment, delete that line from the first objTask code block.
  7. Uncomment the .display line if you want the task opened to add notes.
  8. Get the GetFolderPath function and paste it in the module after this macro.
  9. Select a message, run the macro. Note: if you select more than one message, it creates a task for each message.

 Sub ConvertMessagetoTwoTasks()
    Dim objTask As Outlook.TaskItem
    Dim objMail As Outlook.MailItem
    Dim newAttachment As Outlook.Attachment
    Dim strID As String
    ' Non-default folder
' Get function from http://slipstick.me/qf#GetFolderPath
    Set SPSFolder = GetFolderPath("acct-name\Tasks")
 
For Each objMail In Application.ActiveExplorer.Selection
  Set objTask = Application.CreateItem(olTaskItem)
 
' Create task with message attached
' for local folder
Set newAttachment = objTask.Attachments.Add(objMail, Outlook.OlAttachmentType.olEmbeddeditem)

With objTask
    .subject = objMail.subject
    .DueDate = objMail.ReceivedTime + 3
    .StartDate = objMail.ReceivedTime + 2
    '.Body = objMail.Body
    .Categories = "MOVED"
    .Save
End With
Set MovedTask = objTask.Move(SPSFolder)
    strID = MovedTask.EntryID

Set objTask = Application.CreateItem(olTaskItem)
' create task for default folder
With objTask
    .subject = objMail.subject & " outlook:" & strID
    .DueDate = objMail.ReceivedTime + 3
    .StartDate = objMail.ReceivedTime + 2
    .Body = objMail.Body
    .Categories = "Working"
    .Save
    .Display
End With
      
    Next
    Set objTask = Nothing
    Set objMail = Nothing
End Sub


Set Reminders

To override your default settings for Task reminders (set in Options, Tasks), you can use the ReminderSet and ReminderTime properties.

This example creates a reminder for 6 hrs before the due date or 6 pm the day before. If a reminder time is not set, it will use the default setting for Tasks, usually 8 am on the due date.

Accepted values for ReminderSet are True (on) or False (no reminder)

objTask.ReminderSet = True
objTask.ReminderTime = objTask.DueDate - 0.25

Insert a hyperlink to the message

This code won't work with Outlook.com tasks because the link is removed from the body. If you are using it with a local task folder that does support hyperlinks, add the Dim's to the top of the code and the other lines after the End With in the first sample above.


Dim objInsp As Inspector
Dim objDoc As Word.Document
Dim objSel As Word.Selection

 Set objInsp = objTask.GetInspector
 Set objDoc = objInsp.WordEditor
 Set objSel = objDoc.Windows(1).Selection
 objDoc.Hyperlinks.Add objSel.Range, strLink, "", "", strLinkText, ""
objTask.Save

More Information

The original email-to-task code is at Create a Task from an Email using a Rule.
How to use the VBA Editor

Written by

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Please post long or more complicated questions at Outlookforums.

One response to “Create tasks for outlook.com and a second Tasks folder”

  1. mary tanzy

    For OneNote users, another method is to create a link to a OneNote file; the OneNote file will show the hidden attachments that you have dragged to the Task but cannot see displayed, or you can drag the attachments into the OneNote file itself. To create the link: 1. Open OneNote
    2. Create a new page in the desired section (I have a Getting Things Done section for uncategorized projects and other sections for categorized projects--Vendors, Personnel), using the OneNote button in the Task tab
    3. When the popup window appears prompting you to select a page to link to, select the page you have just created.

Leave a Reply

If the Post Coment button disappears, press your Tab key.