Create a Task from an Email using a Rule

Last reviewed on November 22, 2014   —  147 comments

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, 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 "email@address.com" line. You'll also need to change .Save to .Send

With objTask
    .Assign
    .Recipients.Add "email@address.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 = Application.CreateItem(olTaskItem)
    ' do whatever
    ' 
    objTask.Save

' After you save the task, move it to the other folder
objTask.Move SPSFolder
 

Create the rule

Create a rule to run a scriptCreate 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.

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

Tools

SimplyFile for Microsoft Outlook

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 2.3.4.106.

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.

147 responses to “Create a Task from an Email using a Rule”

  1. Mike Hearn

    Great site with plenty of information thanks a lot.

    I need to set up the address box on outlook 2010 contacts page so that the first line is "home1" and the second line is "home2" third line "home3" etc etc

    I have had a look at the developer and installed and presume that this is the way to set it up.

    Any tips advice or videos to help me please ? Have tried export file but no way can i get the file spilt - though it does recognize the city and post code .

    Many thanks

  2. Jason

    Would it be possible to assign this event to a button (macro) by customizing the toolbar of the message form? I would like to be able to trigger the event while reviewing the message, as opposed to creating the task based on a rule.

  3. Jesse

    Hello,
    After a solid 3 hours of searching for solutions to what I thought would be a standard feature, I was amazed that the code you listed above worked!

    The wrinkle: I would like the created task to be created in a shared task folder rather than my default task folder... ie, I have a custom task folder called "Freight" which can be accessed by anyone in our freight department and I want the auto-generated task to be there.

    Thanks for any (more) assistance you could provide...

  4. Ike

    Thanks for the useful code.

    Is it possible to create a task from an email attachment?

    If I also have multiple attachments in one email is it possible to create multiple tasks i.e. One task is generated for each attached item.

  5. Timo

    This is very helpful site nad excelent code!

    How can I add a red flag for the task. Or is there any other way that I could get my mailconverted tasks to get shown to me more easier. Now I have to go to tasks and select right task list to see these converted.
    if I would get a flag on it it would come up more!

    I am starting these things so...

  6. Jeff

    Great code!

    is it possible to add the first line of the body of the email to a user defined field? My email will have the name of the person sending the request, I have a user defined field in my task for Requested by.

  7. Jon

    Thanks for the very useful code - You are truly Most Valuable!

  8. David

    That is a very useful piece of code, thanks.

    Out of interest, how much additional coding would it take to check if a particular task already existed and update that task rather than creating a new one? e.g. any email coming from address aaa@bbb.com would cause the same task to be updated with the subject line of the email.

  9. Lee Edwards

    CODE LIKE EMAIL TO TASK CAN ANYONE HELP?
    I have an Outlook add-in called Credenza which looks to be based on the Journal feature in OL , is there a way to modify the code so an email could be made into one of these Credenza cases automatically?
    Kind of like email to task just email to case that has a certain format and form?

    http://www.credenzasoft.com/Features/manage.html#

  10. Lee Edwards

    OK and i asked and they said they would make it a product suggestion

    Thanks

  11. Jeffrey Gage

    This works awesome and so grateful I was able to stumble across this tip.
    I have a requirement to move the task into a Task List linked to Sharepoint.
    Would you by chance know how to save the task into the sharepoint list instead of the regular list within Outlook?

  12. Ross Dickerson

    The code is great and worked the first time I tried it. I deleted the test tasks it created, but now it does not create new tasks when I run it. I have tried restarting Outlook, but it still fails. Restarting the computer, and it still fails. The code is still the same in VBA.

    I am in a corporate domain environment. Could that be disabling this functionality?

    Any ideas?

  13. Jon Spector

    I'd like to trigger this script by setting up a rule that runs whenever Outlook receives an email with certain words in the subject line. I am running the Outlook client on several computers, none of which is guaranteed to be running Outlook all the time (i.e. I use a laptop at work, and when I am travelling it is not on). Is the script stored on the Exchange server, so it will be available to run whenever it is triggered by the rule? If not - what happens when the rule triggers the script, but the script is on a machine which is not running?

  14. John

    This script is 90% of what I have been trying to achieve.

    What do you need to add to the script to add the email attachment(s) to the task? This is the last 10%

    Thanks for the script!

  15. John

    So just one "if Item.Attachment.Count..." statement, right?

  16. John

    when I debug, I get: "Compile error: Sub or Function not defined" popup and
    "CopyAttachments" is highlighte.

    I'm not sure I'm inserting the two bits of code in the right place;

    The code:

    If Item.Attachments.Count > 0 Then
    CopyAttachments Item, objTask
    End If

    goes right before the .save statement in the "With objTask..." block

    but where does the CopyAttachments function from the copy appointments macro go?

    TIA,
    JH

  17. Michael

    Dear Diane.
    I would first like to applaud your work - it is right on the point, clearly structured and helpful.
    I have been looking for a pragmatic approach to manage the "to-dos vs. tasks" problem in Outlook for months (if not years). Your solution goes very much into that direction, however I am still trying to figure out if there is a way to also solve the focus on flags and the automatization feature (e.g. with repetitively running script?). I have also found the following code which might be useful for an expert like you (http://xmindlook.net/xmindlook-sync/documentation/tips/email-to-task-conversion).
    I would be very greatful for your help!
    M

    Desired solution:
    Flagged emails shall be automatically (e.g. every couple minutes) converted into corresponding tasks
    Desired behavior:
    * for newly created task (placed in default task folder on exchange, mail itself and mail-attachments included as attachments in task, email subject set as task title, email receival date set as start date in task, other fields like category left empty (will be set manually later on))
    * for original mail (flag disabled (empty), text "[Task] " added at the beginning of the mail subject)

  18. Carlos

    Me sirvió mucho, gracias

  19. Venetia

    Bump!
    :)
    Hi Diana - any chance you have advice on how to setup an auto-rule to a sahred task folder?

  20. Craig

    Diane, you're a genius!

    Would there be a way to look in the body or subject of the email for Due Date data and enter that in the task?

    Many thanks for your work already.

  21. Sharon

    Hi, this site is great! I wanted to use this code but I need it to run when I am not in the office (as I want to send myself emails which will create tasks) - I see from what you say that the code lives on the machine. So, looking at it from a new angle, is it possible to have a macro that runs when I launch Outlook which would check my inbox for emails with "Task" in the subject for example and create tasks when it finds one?

    I hope you can point me in the right direction! Thanks

  22. Sharon

    Thanks very much! This is great.

  23. sarah m

    So easy to use! Thanks. I also added a If unread = true condition so it would only apply the code to new, unread messages. otherwise it kept adding every message that met my conditions, even if they were old, my task list got very long!

  24. Terry T

    Diane I love this macro. I just wish it would not delete the e-mail from the folder. Can you help me out?

  25. Tyler

    Hi Diane -
    I'd like to save the tasks to a sub folder within the default tasks, in other words not on a Sharepoint server -
    Thank you

  26. Jack

    Fantastic stuff - being a newbe when I go to create a rule, it doesn't give me the option of "run a script". what am I doing wrong? thx

  27. Brian

    Is there a way to have the email as an attachment, but NOT have the body of the email pasted into the notes area of the task? I would rather keep that area clean for things I need to know about the task, plus the attachment is already there

  28. Brian

    Perfect! I was able to stop the body text as well as get it to categorize and set dates the way i want. Next question, how can I combine this with the quickflag one you posted earlier? If I forget to BCC myself, I would like to be able to go to the the follow up flag and get the same result. How do I combine that code with what I've already done?

  29. moltra1

    Is there a way to copy the format of the email text to the task. i.e. if the email had tables in it.

  30. Ersula Washington

    Hi Diane,

    I think I might be totally confused and I consider myself an advanced user of Microsoft Office. Since I don't have much experience in the way of writing scripts, is it possible to get a step-by-step of this process? I have been trying to convert my emails into a task by way of creating a rule. Currently, I have a rule setup to create a task but it's just the email sitting in my task folder. Please help!

    Ersula

  31. Jaime

    Can you provide code to the do the same thing, but to also set the DueDate at ReceivedTime + 2 WORK days? I've searched for hours and can't seem to find something I can work with...I am a novice to VB.

  32. Jaime

    In addition to the post above (on 7/12/13), is it possible to create something that would only execute the code if the email is an original email and not a reply or forward of an email? I plan to use this in conjunction with an Outlook rule to run this script if the Subject meets word based criteria. But I would only want it to run on the original email and not any subsequent related emails I might receive. Any help you can provide is much appreciated.

  33. David Deblauwe

    Diane, how/what code would you include in the script to include the recipient/sender of the email to convert into the subject line of the task? Thanks, David

  34. Chris

    Hello, I followed these steps using the first code at the top of this page, last Friday. The rule worked as expected. Came in this morning, and now the script will not run. Everything else in the rule works (alert, pop up notice etc), but the task is not created. Outlook 2010

  35. Chris

    Thank you. That was the problem. Works fine again now.

  36. Dave

    I would like to create 2 tasks for certain emails how would I go about doing this?

  37. Kevin

    Hi Diane,

    I would like to auto assign this task to another team member, how would i do this?

    Thanks

  38. Allen Hopson

    Hello Diane!

    Your coding solves a big issue in my organizational management skills and I thank you! However, I have had the same experience Chris who posted on 9/16/13 - I have followed the steps using the first code at the top of the page - the rule WORKED - now the rule does NOT work - Everything else in the rule works (such as marking item as read), but the task is not created. I checked Macro Settings in Trust Center and the only thing that is checked is "Notifications for digitally signed macros, all other macros disabled". I am running Outlook 2013 (Office 365 Enterprise). Can you help me? I do not understand the security settings in Outlook. Thanks!

  39. Can Kefeli

    Hi Diane,

    I used your code to create task for email with certain words in subject. Also ı want to modify due date of task with information in the email. I tried to use code below but it did not work. Please help me about it

    note: I checked "tarih" in excel and it gets correct date.

    The mail body of email is like below

    NOR-RONA-TRB-ANOP TASKS
    No HYPERLINK "http://kumluca/easyforms/data_details.php?CODE=RINL45F6UHYQ0OV92WZK&FIELD_NAME=No&VALUE=16"16
    Konu:
    2014 Main-Remote çalışması
    Açıklama:
    2014 te yapacağımızı main-remote dönüşümlerini planlayıp süreçleri başlatabilir misiniz?
    İstek Yapan:
    CAN KEFELI
    Toplantı T:

    Hedef T:
    2014-01-31 09:48
    Durum:
    ONAY_BKL
    Sorumlu:
    TCCISAHIN
    Öncelik:
    Normal
    Hafta:
    Y14W03
    Kayıt Tipi:
    Private
    Copyright © Turkcell

    THE CODE:

    Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim tarih As Date
    Dim mesajicerik As String
    Dim tarihyeri As Integer
    Dim objTask As Outlook.TaskItem
    Set objTask = Application.CreateItem(olTaskItem)
    With objTask
    .Subject = Item.Subject
    .StartDate = Item.ReceivedTime
    .Body = Item.Body
    mesajicerik = objTask.Body
    tarihyeri = InStr(1, mesajicerik, "Hedef T: ")
    tarih = DateSerial(Mid(mesajicerik, tarihyeri + 11, 4), Mid(mesajicerik, tarihyeri + 16, 2), Mid(mesajicerik, tarihyeri + 19, 2))
    .DueDate = tarih
    .Save

    End With
    Set objTask = Nothing
    End Sub

  40. Can Kefeli

    Hi Diane,

    thank for the code it work fine but ı want to modify created task due date with information in email. so ı wrote below code but it did not work.

    I checked the variable "tarih" in excel it gets correct date information from email body.Please help me

    Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim tarih As Date
    Dim mesajicerik As String
    Dim tarihyeri As Integer
    Dim objTask As Outlook.TaskItem
    Set objTask = Application.CreateItem(olTaskItem)
    With objTask
    .Subject = Item.Subject
    .StartDate = Item.ReceivedTime
    .Body = Item.Body
    mesajicerik = objTask.Body
    tarihyeri = InStr(1, mesajicerik, "Hedef T: ")
    tarih = DateSerial(Mid(mesajicerik, tarihyeri + 11, 4), Mid(mesajicerik, tarihyeri + 16, 2), Mid(mesajicerik, tarihyeri + 19, 2))
    .DueDate = tarih
    .Save

    End With
    Set objTask = Nothing
    End Sub

  41. Can Kefeli

    Hi again,
    when ı used the code below, it created the tasks buts due date of task is 30.7.2019 so I think ı could not get the right text parts of task body. Is there a way to see which parts I get from the body with code?

    THE CODE

    Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim tarih As Date
    Dim mesajicerik As String
    Dim tarihyeri As Integer
    Dim objTask As Outlook.TaskItem
    Set objTask = Application.CreateItem(olTaskItem)
    With objTask
    .Subject = Item.Subject
    .StartDate = Item.ReceivedTime
    .Body = Item.Body
    mesajicerik = objTask.Body
    tarihyeri = InStr(1, mesajicerik, "Hedef T:")
    tarih = DateSerial(Mid(mesajicerik, tarihyeri + 10, 4), Mid(mesajicerik, tarihyeri + 15, 2), Mid(mesajicerik, tarihyeri + 18, 2))
    .DueDate = tarih
    .Save

    End With
    Set objTask = Nothing
    End Sub

    TASK BODY

    NOR-RONA-TRB-ANOP TASKS
    No HYPERLINK "http://kumluca/easyforms/data_details.php?CODE=RINL45F6UHYQ0OV92WZK&FIELD_NAME=No&VALUE=16"16
    Konu:
    2014 Main-Remote çalışması
    Açıklama:
    2014 te yapacağımızı main-remote dönüşümlerini planlayıp süreçleri başlatabilir misiniz?
    İstek Yapan:
    CAN KEFELI
    Toplantı T:

    Hedef T:
    2014-01-31 09:48
    Durum:
    ONAY_BKL
    Sorumlu:
    TCCISAHIN
    Öncelik:
    Normal
    Hafta:
    Y14W03
    Kayıt Tipi:
    Private
    Copyright © Turkcell

  42. Can Kefeli

    Hi again, I solve the issue with tihs code, thanks. But I could not set reminder active, it changes reminder date but tick near remider was not checked, how can ı do it?

    Sub ConvertMailtoTask(Item As Outlook.MailItem)

    Dim mesajicerik As String
    Dim tarihyeri As Integer
    Dim objTask As Outlook.TaskItem
    Set objTask = Application.CreateItem(olTaskItem)
    With objTask
    .Subject = Item.Subject
    .StartDate = Item.ReceivedTime
    .Body = Item.Body
    mesajicerik = objTask.Body
    tarihyeri = InStr(1, mesajicerik, "Hedef T:")
    .DueDate = Mid(mesajicerik, tarihyeri + 17, 2) & "." & Mid(mesajicerik, tarihyeri + 20, 2) & "." & Mid(mesajicerik, tarihyeri + 12, 4)
    .ReminderTime = .DueDate - 1
    .Save

    End With
    Set objTask = Nothing
    End Sub

  43. Chris

    Hi, I've been using this excellent code successfully for some while. Now I would like to make one small change I'm unsure how to do it. I have created a task form of my own and saved it personal forms library, I have called it "my task". How can I adapt the code to use my form instead of the default task form.

    I think I know what I need to change, but don't know what to change it to!!!

  44. Chris

    Thank you, and if I've saved the custom form in the personal forms library, what should I do?

  45. Nick

    So I followed all the instructions, however when I try to run the rule nothing happens in Outlook, and when I try to force the rule to run it (the "loading window") just disappears.

  46. Nick Harger (@nickharger)

    It still has the same error. It worked for a few moments before the "loading window" goes back to disappearing.

  47. Nick Harger (@nickharger)

    Here is what I have in VB:

    It Works!
    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 = Blank
    Dim newAttachment As Outlook.Attachment
    Set newAttachment = objTask.Attachments.Add _
    (Item, Outlook.OlAttachmentType.olEmbeddeditem)
    .Save
    End With
    Set objTask = Nothing
    End Sub

  48. cir0net

    Hello,

    Thank you all, this VBA Code used to work great for us. We used it with creating / syncing the task to a linked Office 365 Sharepoint-Tasklist.
    Too bad, since the Office 365 2013 Upgrade it´s not working any more. MS changed the sync to outlook feature in a big way. Now new task are created/synced always first as personal tasks and the GetFolderPath function (see below) to move the tasks to the sharepoint list is not working anymore.
    Looking for some help how to make this work again. Is there a way to add a new task-item to sharepoint task list from VBA?
    Thank you in advance for any advice and code samples.

    Move task to Sharepoint List:
    Set SPSFolder = GetFolderPath("SharePoint ListsYour Site - Tasks")
    Set objTask = Application.CreateItem(olTaskItem)
    -- snipped code --
    objTask.Save
    objTask.Move SPSFolder

  49. Mathieu Cote

    This is great and I want it to work. I copy/pasted the code in the article and get a syntax error... does anyone know what to do with this? It happens for the first line of code (Sub ConvertMailtoTask(Item As Outlook.MailItem))

  50. Curt Faulk

    Diane:

    Diane:
    First, the help you provide and columns you write are excellent. And that you have time to reply and provide detailed responses to everyone is amazing. I can't thank you enough.

    I would like to tweak the code a bit so that the resulting task includes the From/Sent/To/Subject info from the email header above the body text of the email. In other words, it would appear just as if you selected a received message, clicked forward, and copied all of the text below the solid line that Outlook inserts above the From: line.

    I'm using both the Outlook Rule to "Create a task from an Email" and the Macro for creating a task from a selected message and will be using any suggestions you provide in each. Thank you very much!

  51. Curt Faulk

    Acuatlly, I figured it out be looking at your code and a little deductive reasoning, here is what worked:

    .Body = "From: " & Item.Sender & vbCrLf & "Sent: " & Item.ReceivedTime & vbCrLf & "To: " & Item.To & vbCrLf & "Subject: " & Item.Subject & vbCrLf & " ------------------------------------------ " & vbCrLf & Item.Body

    Works great. Thanks! (and you're doing a great job keeping up!)

  52. Haik

    Is it possible to create an appointment in the calender with this script, instead of a task?

  53. Haik

    Thanks Diane, I combined some code I found on the internet and tested. This one works with outlook appoinments from email as a script with rules:

    Sub MakeAppointmentFromEmail(item As Outlook.MailItem)
    Dim objAppt As Outlook.AppointmentItem
    Dim objMail As Outlook.MailItem
    Dim strID As String
    strID = item.EntryID

    Set objAppt = Application.CreateItem(olAppointmentItem)

    Set objMail = Application.Session.GetItemFromID(strID)
    objAppt.Subject = objMail.Subject
    objAppt.Start = objMail.ReceivedTime
    objAppt.ReminderSet = True
    objAppt.Mileage = 30
    objAppt.Save

    Set objAppt = Nothing
    Set objMail = Nothing

    End Sub

  54. Haik

    Thank you, it works. Another question: Is it possible to read and write to userdefinedfields from code? For instance a field I called "OneWayTravelDistance". How do I access this userfield from script? Do you have an example?

  55. Mike Mc

    Hi Diane,

    You have very useful information on your site.

    I am wondering if it's possible to get a cell value, say A1, from Excel and set it as the objTask.DueDate and the objTask.ReminderTime. I would assume the format in the cell would have to be mm/dd/yyyy hh/mm. Your help would be greatly appreciated.

  56. Kevin Stanlay

    Hi Diane,
    You have very useful information on the site and I thank you for that.

    I was wondering if it's possible to grab a cell value, say cell A1, from Excel and set it as the objTask.DueDate and objTask.ReminderTime. I think the cell format would have to be like mm/dd/yyyy hh:mm. I'm not sure how to call the Excel sheet and what to set objTask.DueDate and objTask.ReminderTime equal to. Your help is greatly appreciated.

  57. Curt Faulk

    Hi, Diane. Thank you for all your help. I can't seem to get the copy attachments to work.

    Here is my code, I just can't figure out what I've done wrong.

    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
    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 = "From: " & objMail.Sender & vbCrLf & "Sent: " & objMail.ReceivedTime & vbCrLf & "To: " & objMail.To & vbCrLf & "Subject: " & objMail.Subject & vbCrLf & " ------------------------------------------ " & vbCrLf & objMail.Body
    .Categories = "A - Must Do"
    If Item.Attachments.Count > 0 Then
    CopyAttachments Item, objTask
    End If
    .Save
    End With

    Next
    Set objTask = Nothing
    Set objMail = Nothing
    End Sub

  58. Bennett

    Thanks for the help, this works great. I have added custom fields to the task form and renamed it. When I run this script though it always creates the task using the default task form. Is there away I can have it create the task using the custom form I have already made?

  59. Bennett

    I am having some trouble. When I try using the first line of code it prompts me to enter a file path after I enter the published form name. I have the custom form saved in my personal form library but I am not sure what the file path is. When I use the Item.add code it highlights red when I try and save the code and gives me a syntax error when I run it.

    Also I had the word "with" in the name of the custom task form. This appeared to give me issues when running the code. I renamed it removing "with", and I stopped getting that error. Should I not be using "with" in custom form names?
    Thanks,

  60. William Larson

    Thanks for this tutorial,
    I am trying to create 2 tasks from 1 email with the code you provided and a rule to check mail when it arrives. I have been unsuccessful in getting the second task created. Here is my latest attempt (code below). Can you please let me know what I am doing wrong? I have placed it in ThisOutlookSession. The first task is created but I cant get the code to create the second task. Thanks in advance for your help.

    Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim objTask As Outlook.TaskItem
    Set objTask = Application.CreateItem(olTaskItem)
    With objTask
    .Subject = Item.Subject
    .StartDate = Item.ReceivedTime + 1
    .DueDate = Item.ReceivedTime + 1
    .Body = Item.Body
    .ReminderSet = True
    .ReminderTime = objTask.DueDate + 0.4375
    .Save
    End With
    Set objTask = Nothing
    Set objTask = Application.CreateItem(olTaskItem)
    With objTask
    .Subject = "Task 1" & objMail.Subject
    .StartDate = Item.ReceivedTime + 1
    .DueDate = Item.ReceivedTime + 1
    .Body = Item.Body
    .ReminderSet = True
    .ReminderTime = objTask.DueDate + 0.8125
    .Save
    End With
    Set objTask = Nothing

    End Sub

  61. Russ B.

    All of this has been amazing! Thank you! If I wanted to move the email that I created the task from to a sub folder under the inbox what would I need to add? We are non-profit specialty hospital and this simple script has become invaluable to us. Thank you for your generosity in sharing your knowledge!

  62. Kyle

    Hey Guys,

    Sorry to keep this going.

    If I have 2 email accounts on one outlook, how can I specify which account to assign the task to?

    For example,

    Default email is Email1@email.com

    I need to create the task for Email2@email.com

    Both emails are set up on the same outlook. I would like to avoid emailing it, which I cannot seem to get to work either way.

  63. kris

    Hi,
    I want to use email alert sent from sharepoint to convert to a task. I think the Sub ConvertMailtoTask(Item As Outlook.MailItem) in the macro is only converting mail to task. Can you please help.

  64. John

    I've cobbled together an Outlook (2010) email-to-task VBA script that does exactly what I need it to EXCEPT for one thing: I want to copy the name of the Sender to the "Contacts..." field at the bottom of the Task window. Any tips?

    Here's my script:
    Sub TestCopyFullBody()
    Dim objMsg As Outlook.MailItem
    Dim objTask As Outlook.TaskItem

    Set objMsg = Application.ActiveExplorer.Selection(1)
    Set objTask = Application.CreateItem(olTaskItem)
    Call CopyFullBody(objMsg, objTask)
    objTask.Display
    objTask.Categories = objMsg.Categories
    objTask.Subject = objMsg.Subject & " (from: " & objMsg.Sender & ")"
    objTask.Attachments.Add objMsg

    Set objMsg = Nothing
    Set objTask = Nothing
    End Sub
    Sub CopyFullBody(sourceItem As Object, targetItem As Object)
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection
    Dim objDoc2 As Word.Document
    Dim objSel2 As Word.Selection
    On Error Resume Next
    ' get a Word.Selection from the source item
    Set objDoc = sourceItem.GetInspector.WordEditor
    If Not objDoc Is Nothing Then
    Set objSel = objDoc.Windows(1).Selection
    objSel.WholeStory
    objSel.Copy
    Set objDoc2 = targetItem.GetInspector.WordEditor
    If Not objDoc2 Is Nothing Then
    Set objSel2 = objDoc2.Windows(1).Selection
    objSel2.PasteAndFormat wdPasteDefault
    Else
    MsgBox "Could not get Word.Document for " & _
    targetItem.Subject
    End If
    Else
    MsgBox "Could not get Word.Document for " & _
    sourceItem.Subject
    End If
    Set objDoc = Nothing
    Set objSel = Nothing
    Set objDoc2 = Nothing
    Set objSel2 = Nothing
    End Sub

  65. David Nestlebush

    Hello,

    I'm having a couple of issues with the macro below. When I assign it to someone, it is making them the owner (I would like to be the owner and have it assigned to the person), and the start date is being entered 12/31/1899 (and is showing 5000 days late). I'd also like to make sure I have the "Copy Attachement" portion correct.

    Sub ConvertMailtoTask2()
    Dim objTask As Outlook.TaskItem
    Dim objMail As Outlook.MailItem

    Set objTask = Application.CreateItem(olTaskItem)
    For Each objMail In Application.ActiveExplorer.Selection

    objTask.Assign.Recipients.Add "abcde@abcde.com"
    objTask.Subject = objMail.Subject
    objTask.StartDate = ReceivedTime
    objTask.DueDate = Date + 1.5
    objTask.ReminderSet = True
    objTask.ReminderTime = objTask.DueDate - 0.25 ' remind at 6 AM 1 days from now
    objTask.Body = objMail.Body
    If Item.Attachments.Count > 0 Then
    CopyAttachments Item, objTask
    End If
    objTask.Send

    Next
    Set objTask = Nothing
    Set objMail = Nothing
    End Sub

    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

  66. Russ B.

    Thanks for your previous assistance. I have one more question... I get emails that have attached tasks to them, Right now I drag the attachment to the task button then up to the Task folder to get it on my task list. Is there a quick script that I can execute that will take the attachment and move it to my task list? I plan to execute such a script as part of the rule that already grabs these emails and moves them to a specific folder. Any ideas or sample script will be greatly appreciated. Thank you!

  67. Thiago

    Hello Diane,

    Congratulations for your code and for share it with us.

    I'm facing a situation here which I want to create a task from a SENT message using a rule. I can only run a script from a message I receive. Is it possible to run a script from a sent message, using a rule?

    Thanks in advance.

  68. Matthew Schwarz

    Hi. Your site and your examples are very useful (and even fun to read). I have a question: I want to do something similar to above except I want to be able to flag a message for follow-up, and then get a prompt to rename the task to something else. As a super bonus, I would like a prompt to get the flag date picker (choose a start and due date).
    This would be useful for example if I sent an email requirement to a delegate and I bcc myself, then I'd have a rule to catch all incoming bccs and automatically flag them and give me a choice of due date and also let me customize the task title.
    Or if I have an email that requires action from me I could use this script to flag it with a choice of start date and then prompt to let me customize the task title.
    Thank you for any attention you can provide.

  69. Alexis Hernandez

    Hello Diane,

    This seems to have worked for me however when doing tests I'm not receiving a 'completed' status report. When manually creating a task, there's a check box that needs to be selected in order to receive updates... is there a way to get this into a code? I hope you can help. thanks so much in advance.

  70. Alexis Hernandez

    Thanks for the quick reply! However, I tried this as stated in your original notes. It is not sending a status report to the sender from the recipient once the task is marked complete. I need the 'Completed status report' to be sent to the sender.

Leave a Reply

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