I regularly convert many of my emails into tasks, is there a way to create a rule that will automatically convert emails with a specific subject line, into a task?
Sure, you can use a simple script that creates a task from an email and use it with a Run a Script rule. We also added a second code sample that creates a task from the message you are reading in the reading pane.
To create an appointment from an email message, see Create an Outlook appointment from an email message.
VBA to Convert an Email to a Task
Press Alt+F11 to open the VBA editor and expand the tree to find ThisOutlookSession. Paste this code into the VBA editor then create a rule and choose Run a script as the action.
Sub ConvertMailtoTask(Item As Outlook.MailItem) Dim objTask As Outlook.TaskItem Set objTask = Application.CreateItem(olTaskItem) With objTask .Subject = Item.Subject .StartDate = Item.ReceivedTime .Body = Item.Body .Save End With Set objTask = Nothing End Sub
You can customize the script to set a category or due date (or any other fields supported in Tasks). To calculate the due date, you'll use the DueDate property and add a whole number to the Received date. If you prefer to change the Start date, you would add a whole number to the start date line. If you use a category that is not in your Categories list, the color category field in the view will be colorless as the category is not in the master list.
objTask.StartDate = Item.ReceivedTime + 2 objTask.DueDate = Item.ReceivedTime + 3 objTask.Categories = "Slipstick"
To use today's date only, not the current time, use Date and decimals to set the due date or reminder time.
.DueDate = Date + 3.5 '3 days at noon .ReminderTime = Date + 2.25 ' remind at 6 AM 2 days from now
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
Create a task using a Run a Script rule video tutorial
Working with Attachments
To add the item as an attachment to the task, add the following lines after the Item.Body line:
Dim newAttachment As Outlook.Attachments Set newAttachment = objTask.Attachments newAttachment.Add Item, olEmbeddeditem
To copy attachments from the messages to the task, you need to use the CopyAttachments, added to the end of the task macro.
Add this code before the .save
If Item.Attachments.Count > 0 Then CopyAttachments Item, objTask End If
Then this after the end of the first macro:
Sub CopyAttachments(objSourceItem, objTargetItem) Set fso = CreateObject("Scripting.FileSystemObject") Set fldTemp = fso.GetSpecialFolder(2) ' TemporaryFolder strPath = fldTemp.Path & "\" For Each objAtt In objSourceItem.Attachments strFile = strPath & objAtt.FileName objAtt.SaveAsFile strFile objTargetItem.Attachments.Add strFile, , , objAtt.DisplayName fso.DeleteFile strFile Next Set fldTemp = Nothing Set fso = Nothing End Sub
Send a Task Request
If you want to send a Task Request, you need to Assign it and add the Recipient. You can use either the full email address or the GAL alias, or even the person's display name, provided the name can resolve to an entry in your address book or GAL. I recommend using the address only because it can't resolve to the wrong person.
You'll need to add .Assign to the With objTask code block, along with .Recipients.Add "firstname.lastname@example.org" line. You'll also need to change .Save to .Send
With objTask .Assign .Recipients.Add "email@example.com" .Subject = Item.Subject .StartDate = Item.ReceivedTime .Body = Item.Body .Send End With
If you use the user's name or alias, you may need to Resolve it using code before it's sent. .Assign goes in the With objTask code block, but the Recipient is added outside of the With statement, then it's sent.
The DIM statement goes at the top of the macro with the other DIM statements.
Dim myDelegate As Outlook.Recipient With objTask .Assign .Subject = Item.Subject .StartDate = Item.ReceivedTime .Body = Item.Body End With Set myDelegate = objTask.Recipients.Add("alias") myDelegate.Resolve objTask.Send
Add Categories to the tasks
Carol asked how to add a category to the tasks. This is easy if you want one category for all tasks - just place this line before the objTask.Save line:
objTask.Categories = "keyword"
To assign different categories based on different keywords in the subject, you can use an IF statement for a couple of keywords but should use an array for a larger number of keywords. Instructions are at Using Arrays with Outlook macros.
Save to a different tasks folder
You can save the task to a different folder by adding two lines to the code. This example saves it to a Task folder in a different data file, in this case, a Sharepoint task list that is linked to Outlook.
You can also use a different folder in the mailbox. When the folder is the same level as the Tasks folder, using the example below.
Set SPSFolder = Session.GetDefaultFolder(olFolderTasks).Parent.Folders("Task folder Name")
When the folder is a subfolder under the default Tasks folder, use this:
Set SPSFolder = Session.GetDefaultFolder(olFolderTasks).Folders("Subfolder Name")
See Working with non-default Outlook Folders for more information.
' You need the GetFolderpath function from 'http://slipstick.me/qf#GetFolderPath Set SPSFolder = GetFolderPath("SharePoint Lists\Slipstick - Tasks") Set objTask = SPSFolder.Items.Add(olTaskItem) ' do whatever ' objTask.Save
Create the rule
Create a rule using the condition and choose the action "Run a Script", choosing the ConvertMailtoTask script you pasted into the VBA editor. Complete the rule.
When a new message arrives meeting the conditions in the rule, the script runs and creates a task out of the message.
Create Task from the selected message
Jason wanted to know if we could use the code with a button to create a task from a selected message.
To do this, we needed to modify the original code just a little. To use it, create a command on the ribbon or toolbar and assign the macro to it. When you are reading a message in the reading pane, you can click the button to create a task.
This code doesn't work with open messages, but a little more tweaking can change that. Simply change the Set objMail line to Set objMail = GetCurrentItem() and get the GetCurrentItem function from "Outlook VBA: Work with Open Item or Selected Item".
To use, select the message and run the macro.
Sub ConvertSelectedMailtoTask() Dim objTask As Outlook.TaskItem Dim objMail As Outlook.MailItem Set objTask = Application.CreateItem(olTaskItem) Set objMail = Application.ActiveExplorer.Selection.Item(1) With objTask .Subject = objMail.Subject .StartDate = objMail.ReceivedTime .Body = objMail.Body 'Add the message as an attachment .Attachments.Add objMail .Save End With Set objTask = Nothing Set objMail = Nothing End Sub
SimplyFile helps you file incoming and outgoing messages to the right Outlook folder with one click of a mouse. SimplyFile's state of the art algorithm learns as you file messages and suggests destination folders for filing. All you have to do to send a message to the right folder is click a button. SimplyFile also includes buttons for turning messages into Tasks and Appointments. Compatible with Outlook 2000, 2002, 2003 and 2007. Version 184.108.40.206.
How to use macros
First: You will need macro security set to low during testing.
To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.
After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
More information as well as screenshots are at How to use the VBA Editor
Other macros to create tasks or appointments are at
- Automatically create a task when sending a message
- Create an Outlook Appointment from a Message
- Create Task or Appointment and Insert Selected Text
- Create Tasks from Email and move to different Task folders
- How to set a flag to follow up using VBA
- Replicate GTD: Create a task after sending a message