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.
With objMsg .MarkAsTask olMarkThisWeek .TaskDueDate = Date + 3.5 '3 days at noon .FlagRequest = "Call " & objMsg.SenderName .ReminderSet = True .ReminderTime = Date + 2.25 ' remind at 6 AM 2 days from now .Save End With
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.Attachment Set newAttachment = objTask.Attachments.Add _ (Item, Outlook.OlAttachmentType.olEmbeddeditem)
To copy attachments from the messages to the task, get the CopyAttachments function and add it at the end of the task macro. Then add this code before the .save
If Item.Attachments.Count > 0 Then CopyAttachments Item, objTask End If
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 = objMail.Subject .StartDate = objMail.ReceivedTime .Body = objMail.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 = objMail.Subject .StartDate = objMail.ReceivedTime .Body = objMail.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 = Application.CreateItem(olTaskItem) ' do whatever ' objTask.Save ' After you save the task, move it to the other folder objTask.Move SPSFolder
Create 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.
Sub ConvertSelectedMailtoTask() Dim objTask As Outlook.TaskItem Dim objMail As Outlook.MailItem Set objTask = Application.CreateItem(olTaskItem) For Each objMail In Application.ActiveExplorer.Selection With objTask .Subject = objMail.Subject .StartDate = objMail.ReceivedTime .Body = objMail.Body .Save End With Next 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 126.96.36.199.