This macro was originally written to work around an issue with the "old" Outlook.com server but now that Outlook.com is hosted on Office 365, Tasks work "as expected" and fully support attachments. However, you can use this method to copy Tasks (or with a little tweaking, other Outlook items) to another folder in your profile.
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 macros on this page. The first macro creates a task with a text link to the original message. This method can be used with iCloud addin to link to the original message in your mailbox. (The link will only work in Outlook, not from your iPhone.)
The second macro creates a task in a local task folder (that supports attachments) and creates a copy of the task (without the attachment) in another 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.
Create a 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:
- Set macro security to low during testing. You can sign it using selfcert later.
- Open VBA Editor using Alt+F11
- Right click on Project1 and choose Insert > Module.
- Paste the code into the module.
- 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
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 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 Tasks 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:
- Set macro security to low during testing. You can sign it using selfcert later.
- Open VBA Editor using Alt+F11
- Right click on Project1 and choose Insert > Module.
- Paste the code below into the module.
- Edit the folder path for the local folder
- If you don't want the message body in addition to the attachment, delete that line from the first objTask code block.
- Uncomment the .display line if you want the task opened to add notes.
- Get the GetFolderPath function and paste it in the module after this macro.
- 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 fromhttp://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 iCloud 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
Diane,
This was fantastic...thanks. I modified it to create a new task in my PST based on a currently selected task. My particular workflow involves attaching multiple objects to a task when they're related...could be e-mails, documents, or whatever. When I have a task that I want to put an attachment into, I use this macro to automatically create the linked task.
Sub CreateLinkedAttachmentTask()
Dim objTask As Outlook.TaskItem
Dim linkTask As Outlook.TaskItem
Dim strID As String
' Non-default folder
Set SPSFolder = GetFolderPath("myPSTTasks")
For Each objTask In Application.ActiveExplorer.Selection
Set linkTask = Application.CreateItem(olTaskItem)
' create the task that will hold attachments
With linkTask
.Subject = objTask.Subject
.Body = objTask.Body
.Save
End With
' move it to the local pst and get a link to it
Set movedTask = linkTask.Move(SPSFolder)
strID = movedTask.EntryID
movedTask.Display
' update the subject of the current task with the link
With objTask
.Subject = objTask.Subject & " outlook:" & strID
.Body = "See linked task"
.Save
End With
Next
Set objTask = Nothing
Set linkTask = Nothing
End Sub
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.