• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Create a Task from an Email using a Rule

Slipstick Systems

› Outlook › Rules, Filters & Views › Create a Task from an Email using a Rule

Last reviewed on April 8, 2025     338 Comments

A security update disabled the Run a script option in the rules wizard in Outlook 2010 and all newer Outlook versions. See Run-a-Script Rules Missing in Outlook for more information and the registry key to fix restore it.

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 "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 = 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.
Create a rule to run a script

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
 

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.

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:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

More Information

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
Create a Task from an Email using a Rule was last modified: April 8th, 2025 by Diane Poremsky
Post Views: 129

Related Posts:

  • Create a Task and copy to another Tasks folder
  • Automatically create a task when sending a message
  • Create a Series of Tasks Leading up to an Appointment
  • Create Task or Appointment and Insert Selected Text

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

Comments

  1. Josh says

    April 18, 2023 at 11:29 am

    Hello,

    How should one edit the code to have the attachments (and the email) inserted at the top of the body of the task?

    Thanks!

    Reply
  2. Brian Stone says

    January 27, 2023 at 2:13 am

    Thank you for the help! Wonderful tutorial! I am confused on the step to add the created task to a custom "task list" (screenshot attached)

    Any help would be much appreciated.

    Reply
  3. Brian Stone says

    January 26, 2023 at 5:09 am

    Hi Diane

    Thank you so much for the clear wonderful instruction! Everything is working except when the mail comes in I would like the task to be created within a custom named "list"

    I would love for the task to be created in the list in this screenshot.

    Reply
    • Diane Poremsky says

      January 26, 2023 at 9:08 am

      For that you need to get the folder path - if the task folder is in the accounts data file:
      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")

      Then this to create it:
      Set objTask = SPSFolder.Items.Add(olTaskItem)
      ' do whatever
      '
      objTask.Save

      If its in another data file, you need to get the folder path:
      ' 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

      Reply
      • Brian Stone says

        February 1, 2023 at 5:39 am

        Dear Diane

        Thank you so much, I'm afraid I'm still not quite sure where I am going wrong, what would I add to the script I have?

        Sub ConvertMailtoTask(Item As Outlook.MailItem)
            Dim objTask As Outlook.TaskItem
            Set objTask = Application.CreateItem(olTaskItem)
            Set SPSFolder = Session.GetDefaultFolder(olFolderTasks).Parent.Folders("RedBerries")
        With objTask
            .Subject = Item.Subject
            .StartDate = Item.ReceivedTime
            .Body = Item.Body
             Dim newAttachment As Outlook.Attachments
        
        
         Set newAttachment = objTask.Attachments
           newAttachment.Add Item, olEmbeddeditem
           If Item.Attachments.Count > 0 Then
        CopyAttachments Item, objTask
        End If
            .Save
        End With
            Set objTask = 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
        

        Apologies, still learning.

        Kind Regards

  4. Sherlin says

    June 14, 2021 at 4:32 am

    I think the other way to do this to create "Quick Steps".
    In the Home tab, click on "Create New" under "Quick Steps" category. Refer below link for more information
    Automate common or repetitive tasks with Quick Steps - Outlook (microsoft.com)

    Reply
    • Diane Poremsky says

      June 14, 2021 at 7:18 am

      That method is not automatic (a rule is) and a macro can copy the message body exactly - the quick step adds a to/from header and removes images. It also only uses the default tasks folder. A macro can use any task folder in your profile.

      Reply
  5. Cischology says

    June 8, 2021 at 9:49 am

    Thank you so much for share this. I tried your code and the only thing that is not working and I am having an issue with, how do I make the email as an attachment in the task created?

    Reply
    • Diane Poremsky says

      June 9, 2021 at 12:25 am

      Do you have macro security set to low? If not, outlook might be blocking it.

      This will add the message as an attachment -
      'Add the message as an attachment
        .Attachments.Add objMail

      Reply
      • cischology says

        June 9, 2021 at 3:34 pm

        Thank you for your quick reply, however, it does not seem to change anything no matter which option I chose.

      • Diane Poremsky says

        June 9, 2021 at 6:35 pm

        Oh, wait. I think I misread - the macro works, just not adding an attachment.

        you are declaring the mail item as 'item' in the first line - so you need to use item here-

         .Attachments.Add item

        Sorry for misunderstanding.

      • cischology says

        June 10, 2021 at 5:51 pm

        Thank you so much. Can you please also assist me with a way on how I can eliminate duplicated tasks? or some times I get the same email twice so instead of having duplicate task the code will check for it and create the task once.
        Sorry I am not too savvy with VBA. TIA

      • Diane Poremsky says

        June 10, 2021 at 9:47 pm

        I'll have to think on the best way to do this - duplicate checking macros can be slow.

  6. Edward says

    January 14, 2021 at 10:46 am

    Hi Diane - hoping you are well.

    I've looked at a variety of your codes and found one that will automatically create a task based on sending an email that contains a category - I will paste it below with my minor changes.

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    'Updated by Extendoffice 20181123

    If Item.Categories <> "3 month follow up" Then
     Exit Sub
    End If
       
      Dim xYesNo As Integer
      Dim xPrompt As String
      Dim xTaskItem As TaskItem
      Dim xRecipient As String
      On Error Resume Next
      xPrompt = "Do you want to create a task for this message?"
      xYesNo = MsgBox(xPrompt, vbYesNo + vbInformation, "3 Month Follow Up")
      Cancel = False
      If xYesNo = vbNo Then Exit Sub
      Set xTaskItem = Application.CreateItem(olTaskItem)
      For Each Rcp In Item.Recipients
        If xRecipient = "" Then
          xRecipient = Rcp.Address
        Else
          xRecipient = xRecipient & vbCrLf & Rcp.Address
        End If
      Next Rcp
      xRecipient = xRecipient & vbCrLf & Item.Body
      With xTaskItem
        .Subject = Item.Subject
        .StartDate = Item.ReceivedTime
        .DueDate = Date + 84 + CDate("8:00:00 AM")
        .ReminderSet = True
        .ReminderTime = Date + 84 + CDate("8:00:00 AM")
        .Body = xRecipient
        .Save
      End With
      Set xTaskItem = Nothing
    End Sub

    This code works as it should and will populate the task. However, in my case, I'm trying to add additional categories with different follow up times; eg. if category 1 is applied in the email, set task to 7 days, if category 2 set task to 14 days etc. and I dont know how to add that into this code? I'm sure its copy/pasting only a small fraction of the actual entire code? Additionally, I noticed that when these tasks are created, and I go to the "to-do" list, their color code is not flagged beside the task? Is it possible to change that and perhaps remove the prompt? I'm hoping you or someone might be able to help with this edit? It would make my life so much simpler!

    Reply
    • Diane Poremsky says

      June 9, 2021 at 12:31 am

      you need to use an if statement - probably in a select case to cover each category -
      if item.categories = "category 1" then
       .ReminderTime = Date + 14 + CDate("8:00:00 AM")
      end if

      using select case will allow you to do something like this:

      select case item.categories

      case "category 1"
      lRemind = 14

      case "category 2"
      lremind = 28

      end select

      Then you will use

      .ReminderTime = Date + lremind + CDate("8:00:00 AM")

      Reply
  7. CharlesC says

    October 23, 2020 at 10:20 am

    Hi Diane,

    I Just want to sincerely thank you for all the valuable information you contribute. It has literally saved me days of work.

    Reply
  8. Neil says

    August 24, 2020 at 10:24 pm

    Hi Diane I'm new to VBA but enjoying the cool features we can add like changing the subject line, reply all with attachment and automatically creating a task if someone sends me an email with "can you" [do something] in the body.

    The create task wors fine but the maco doesn't seem to add the email as an attachment - for example in Outlook 365 you can drag an email to the to-do and it will maintain the email so when you click on the task it brings up the email.

    Any thoughts? thanks!

    Reply
    • Diane Poremsky says

      August 25, 2020 at 1:06 am

      The last macro should add it as an attachment -
      'Add the message as an attachment
        .Attachments.Add objMail

      Reply
    • Neil says

      August 25, 2020 at 7:58 am

      Hi - thanks but I think I broke it...code is below - any thoughts would be appreciated!
      Sub ConvertMailtoTask(Item As Outlook.MailItem)
        Dim objTask As Outlook.TaskItem
        Set objTask = Application.CreateItem(olTaskItem)
      With objTask
        .Subject = Item.Subject
        .StartDate = Item.ReceivedTime
        .DueDate = Item.ReceivedTime + 1
        .Importance = olImportanceHigh
        .Body = Item.Body
        Dim newAttachment As Outlook.Attachments
        Set newAttachment = objTask.Attachments
        newAttachment.Add Item, olEmbeddeditem
        If Item.Attachments.Count > 0 Then
        CopyAttachments Item, objTask
        .Attachments.Add objMail
      End If
        .Save
      End With
        Set objTask = Nothing
      End Sub

      Reply
      • Neil says

        August 28, 2020 at 6:04 am

        changed ot this - seems ot work

        Sub CreateNewTask(Item As Outlook.MailItem)
        Dim xNewTask As TaskItem
        On Error Resume Next
        Set xNewTask = Outlook.CreateItem(olTaskItem)
        With xNewTask
        .Subject = Item.Subject
        .StartDate = Item.ReceivedTime
        .DueDate = Item.ReceivedTime + 1
        .Body = Item.Body
        .Importance = olImportanceHigh
        .Save
        End With
        Set xNewTask = Nothing
        End Sub

  9. Rob says

    August 21, 2020 at 5:46 pm

    in the .Subject = item.subject , what if I want to add additional text to the subject for example the word Follow up: Subject

    Reply
    • Diane Poremsky says

      August 25, 2020 at 1:04 am

      Use
      .Subject = "followup: " & item.subject

      Reply
  10. Kimberly Cope says

    June 2, 2020 at 10:39 am

    Hi Diane, I'm wondering if there is a way (or script) that would send an email from the inbox straight to a folder (say '2020') after it has been turned into a task with attachment.

    Reply
    • Diane Poremsky says

      August 25, 2020 at 1:02 am

      Yes, the macro can move the message. Use
      objMail move [folder]

      Reply
  11. RMK says

    August 13, 2019 at 5:48 pm

    I am interested in setting a script/macro to look at uncategorized tasks in a specific task folder and assign a category to them. Has anyone written code to have a script tick through each task in an a folder and do that?

    Reply
    • Diane Poremsky says

      August 13, 2019 at 5:55 pm

      I don't have a macro that does exactly that, but it wouldn't be too hard to do. I have a macro that touches all item in a folder and you'd just need to check for a category and assign one if missing.
      https://www.slipstick.com/developer/code-samples/working-items-folder-selected-items/

      Reply
      • RMK says

        August 13, 2019 at 9:33 pm

        Awesome! Would you share it (or did I miss it)?

      • Diane Poremsky says

        August 13, 2019 at 9:59 pm

        No, i don't have a macro that does it that is ready to use, but its simple to do. Using the all items/selected folder macro at the link I posted, add this where is says to do whatever/ debug.print .subject

        If .Categories = "" Then
        .Categories = "My New Category"
        .Save
        End If

  12. MTR says

    February 20, 2019 at 10:12 am

    Thank you very much for all your help with this. I am new to this and having two issues.

    I would like to add the items to a new folder under My Tasks. It would be a folder under my tasks - similar to "To Do List" / "Tasks", but the folder I would like it to be inserted in would be "Follow Up". I cannot get the email to be added to this.

    Also, I would like to new task item to have the original category of the email, as well as an added category when it was added to tasks so the rule does not put duplicates in.

    Can you help me with this?

    Sub ConvertFUMailtoTask(Item As Outlook.MailItem)
    Dim objTask As Outlook.TaskItem
    Set SPSFolder = Session.GetDefaultFolder(olFolderTasks).Folders("Follow Up")
    Set objTask = SPSFolder.Items.Add(olTaskItem)
    objTask.Save
    With objTask
    .Subject = Item.Subject
    .StartDate = Item.ReceivedTime
    .Body = Item.Body
    Dim newAttachment As Outlook.Attachments

    Set newAttachment = objTask.Attachments
    newAttachment.Add Item, olEmbeddeditem
    .DueDate = Item.ReceivedTime + 7
    If Item.Attachments.count > 0 Then
    CopyAttachments Item, objTask
    End If
    objTask.Categories = Item.Categories
    Item.Categories = "Assigned [Task]"
    .Save
    End With
    Set objTask = Nothing
    End Sub

    Reply
    • MTR says

      February 20, 2019 at 10:14 am

      Photo of code attached. I am using Outlook 365.

      Reply
    • MTR says

      February 20, 2019 at 11:50 am

      For reference I am using Office 365.

      Reply
    • Diane Poremsky says

      March 2, 2019 at 12:40 pm

      Do you receive any error messages? It looks like it should work.

      Reply
  13. AUBREY says

    June 13, 2018 at 11:34 am

    Thanks again Diane,

    After 10 hours of tinkering I was able to get the macro to create the task in my Sharepoint folder.AWEEEEEEESOME SAUUUUCE.

    Cannot Thank you enough. Able to make the Help Desk I've always wanted

    Reply
    • Diane Poremsky says

      June 13, 2018 at 10:59 pm

      What was the secret trick? It may help others facing the same problem.

      Reply
      • AUBREY says

        June 16, 2018 at 3:57 am

        Hi Diane,

        I had a mix up of statements. I had "Set objTask = SPSFolder.Items.Add(olTaskItem)
        objTask.save"

        Once I changed it too ""Set NewTask = SPSFolder.Items.Add(olTaskItem)
        NewTask.save"

        Everything started working fine. The only minor issue I have is the Macro settings in Outlook. When I Sign the macro and set to "Notifications for digitally signed macros..." It does not run.

        When I switch it back to "Notifications for all macros" it works.

        Other than that, it works perfect.

      • Diane Poremsky says

        June 16, 2018 at 9:40 am

        >> Macro settings in Outlook. When I Sign the macro and set to "Notifications for digitally signed macros..." It does not run.
        Did you try making a new certificate? Quite a few people had problems after a recent update and had to make a new certificate.

      • AUBREY says

        June 16, 2018 at 5:36 pm

        I will try that and let you know. Thanks again. Your site has been very useful.

  14. AUBREY says

    June 13, 2018 at 8:34 am

    Hi Diane,

    Thank you for sharing your script. I was able to get the auto-tasks going just fine. But trying to save or move the task to a Sharepoint Task that I am using for a help desk.

    I cannot seem to get it to save to the folder under "Other Tasks"

    Reply
    • Diane Poremsky says

      June 13, 2018 at 11:01 pm

      >> I cannot seem to get it to save to the folder under "Other Tasks"
      You need to add it to the path -
      Dim subtaskfolder as folder
      Set subtasks = spsfolder.folders("Other Tasks") should do it. (if its a subfolder of the team tasks)

      Reply
      • AUBREY says

        June 16, 2018 at 2:48 am

        once i corrected some of the statements in the code it cleared everything up. I have a mix of "Set objTask" and "Set NewTask". I used your "GetFolderPath" Function and it all worked fine.

  15. Ankit says

    May 7, 2018 at 9:08 am

    Hello Diane,

    Can you tell me how that can be achieved ? Currently I have to manually assign task to team members. I wanted to trigger a mail to my team member and that task should automatically to him/her.

    Thank You.

    Reply
    • Diane Poremsky says

      May 9, 2018 at 12:23 am

      To create a task request to send, use .assign and add a recipient, and .send

      With objTask
      .Assign
      .Recipients.Add "email@address.com"
      .Subject = Item.Subject
      .StartDate = Item.ReceivedTime
      .Body = Item.Body
      .Send
      End With

      Reply
  16. Ankit says

    April 26, 2018 at 3:38 am

    Hi Diane,

    I dont want to hard code any email address. I just wanted to assign the task automatically to a person whom I am sending mail to. Is that possible via script ?

    Thanks,
    Ankit

    Reply
    • Diane Poremsky says

      April 27, 2018 at 12:03 am

      Yes, you can pick up an address from a message.

      Reply
  17. Ankit says

    April 19, 2018 at 10:48 am

    Hi Diane, I am able to resolve all my issues and now it is working fine for me.
    However I am not able to Assign task to person whom I am sending mail to. Can you please help me with that ?

    Reply
    • Diane Poremsky says

      April 19, 2018 at 11:18 am

      did you add
      .Assign
      .Recipients.Add "email@address.com"
      to the task code? Change .Display to .Send (or send it yourself). If the task is not in your default task folder, it won't automatically update.

      Reply
  18. Luis castanheiro says

    April 19, 2018 at 9:06 am

    I updated the scrip to include the copying attachments ( as instructed above) and now it does not work anymore. and some of the code is in red.
    This is what I have now.
    Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim objTask As Outlook.TaskItem
    Dim newAttachment As Outlook.Attachments
    Set objTask = Application.CreateItem(olTaskItem)
    With objTask
    .Subject = Item.Subject
    .StartDate = Item.ReceivedTime
    .DueDate = Item.ReceivedTime + 2
    .ReminderSet = True
    .ReminderTime = Date + 1.5
    .Body = Item.Body
    Set newAttachment = objTask.Attachments
    newAttachment.Add Item, olEmbeddeditem
    If Item.Attachments.Count > 0 Then
    CopyAttachments Item, objTask
    End If
    .Save
    End With
    Set objTask = 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

    Reply
    • Diane Poremsky says

      April 19, 2018 at 1:32 pm

      The code is using html code. i'm adding extra spaces so they aren't converted to the html character - and if the character is messed up, what it is supposed to be is in parenthesis
      & amp ; should be & (ampersand)
      & gt ; is > (greater than)

      Reply
      • Luis castanheiro says

        April 19, 2018 at 2:39 pm

        Hello Diane, made those changes and the red disappeared. However, still not working no task gets created. when I compile the code I get an error Ambiguous name detected. please see attached screen shot. Your help is appreciated.
        Thanks

      • Diane Poremsky says

        April 19, 2018 at 4:02 pm

        that means you have the copy attachments sub in another module - you only need one copy, any macro that needs it will share the one copy. Delete the one in this module.

      • Luis castanheiro says

        April 19, 2018 at 4:06 pm

        Hello Diane, i made the correction as indicated but it still not working. I get an error of "ambiguous name detected" when the project is complied as you can see in the attached screen clip.
        Can you help?
        Thanks

      • Diane Poremsky says

        April 19, 2018 at 4:10 pm

        Remove that CopyAttachments macro - you have a second copy of it somewhere.

  19. Ankit says

    April 19, 2018 at 6:29 am

    Apologies for troubling you Diane but I think I am missing something very basic here. Even after adding GetFolderPath function to code and making other adjustments, it is not giving me desired output.

    Here is the latest glimpse of code -

    Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim objTask As Outlook.TaskItem
    Set SPSFolder = GetFolderPath("Other Tasks\Action_Item_Tracker")
    Set objTask = SPSFolder.Items.Add(olTaskItem)

    With objTask
    .subject = Item.subject
    .StartDate = Item.ReceivedTime
    .Body = Item.Body
    .Display
    .Save
    End With
    Set objTask = Nothing
    End Sub

    Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
    Dim oFolder As Outlook.Folder
    Dim FoldersArray As Variant
    Dim i As Integer

    On Error GoTo GetFolderPath_Error
    If Left(FolderPath, 2) = "\\" Then
    FolderPath = Right(FolderPath, Len(FolderPath) - 2)
    End If
    'Convert folderpath to array
    FoldersArray = Split(FolderPath, "\")
    Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
    If Not oFolder Is Nothing Then
    For i = 1 To UBound(FoldersArray, 1)
    Dim SubFolders As Outlook.Folders
    Set SubFolders = oFolder.Folders
    Set oFolder = SubFolders.Item(FoldersArray(i))
    If oFolder Is Nothing Then
    Set GetFolderPath = Nothing
    End If
    Next
    End If
    'Return the oFolder
    Set GetFolderPath = oFolder
    Exit Function

    GetFolderPath_Error:
    Set GetFolderPath = Nothing
    Exit Function
    End Function

    Reply
    • Diane Poremsky says

      April 20, 2018 at 12:23 am

      for the format of this path is \\datafile display name\folder\subfolder
      Set SPSFolder = GetFolderPath("Other Tasks\Action_Item_Tracker")
      the path as you have it is the data file name in the folder list is "Other Tasks"
      To get the data file name and path, right click on the Action_Item_Tracker folder, choose Properties - the path will be there. Don't use the leading \\ in the macro.

      Reply
  20. Luis castanheiro says

    April 18, 2018 at 4:46 pm

    Hi does this work with Microsoft Office 365? i can't get it to work, mainly because i do not see an option for run script in create a rule.
    Please help

    Reply
    • Diane Poremsky says

      April 18, 2018 at 11:26 pm

      It works, but i forgot to update this run a script page with an important announcement - you need to use a registry key to enable run a script rules now. https://www.slipstick.com/outlook/rules/outlook-2016-run-a-script-rules/

      Reply
  21. Ankit says

    April 18, 2018 at 3:00 am

    Yes, it is still not working for me. Just to add one information that task folder where I want to create a new task is a sync up folder with SharePoint List. Does this make any difference in the code ?

    Reply
    • Diane Poremsky says

      April 18, 2018 at 9:09 am

      oh, yes. The current code uses a subfolder in the default folder. You need to use the folder that syncs with sharepoint.
      ' You need the GetFolderpath function from
      'http://slipstick.me/qf#GetFolderPath
      Set SPSFolder = GetFolderPath("SharePoint Lists\Slipstick - Tasks")
      Set objTask = SPSFolder.Items.Add(olTaskItem)

      Reply
      • Diane Poremsky says

        April 18, 2018 at 9:17 am

        For your example in an earlier comment, the path would be something like

        Set SPSFolder = GetFolderPath("SharePoint Lists\Stericycle_Program_Site - Action Item Tracker")

  22. Ankit says

    April 16, 2018 at 10:03 am

    Hello Diane,

    I have added .Display as suggested by you but still it is not working. Also , I have tried .CreateItem instead of .Add function but still no changes happened. Could you please check and suggest ?

    View to latest code -

    Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim objTask As Outlook.TaskItem
    Set SPSFolder = Session.GetDefaultFolder(olFolderTasks).Folders("Stericycle_Program_Site - Action Item Tracker")
    Set objTask = SPSFolder.CreateItem(olTaskItem)

    With objTask
    .subject = Item.subject
    .StartDate = Item.ReceivedTime
    .Body = Item.Body
    .Save
    .Display
    End With
    Set objTask = Nothing
    End Sub

    Reply
    • Diane Poremsky says

      April 16, 2018 at 12:31 pm

      i will test it, but you definitely need to use .add - create item uses the default folder.

      Reply
      • Ankit says

        April 17, 2018 at 2:53 am

        Please let me know if I need to do some changes in existing code.

      • Diane Poremsky says

        April 17, 2018 at 11:36 pm

        The code works fine here. Is it still erroring for you?

  23. Ankit says

    April 13, 2018 at 1:57 am

    Hi Team, I am new to VB scripting. Based on your article, I have written below code. Not sure why it is still not working. Can you please check -

    Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim objTask As Outlook.TaskItem
    Set SPSFolder = Session.GetDefaultFolder(olFolderTasks).Folders("Action_Item_Tracker")
    Set objTask = SPSFolder.Items.Add(olTaskItem)

    With objTask
    .subject = Item.subject
    .StartDate = Item.ReceivedTime
    .Body = Item.Body
    .Save
    End With
    Set objTask = Nothing
    End Sub

    There has been no error messages encountered. Also, nothing happens with this code. Plz help !

    Reply
    • Diane Poremsky says

      April 13, 2018 at 9:20 am

      Add .Display before or after .Save - this will bring it up on the screen you can see how it look.

      Add this to the module and step into it and watch the each line execute. (It works fine here - the task went into a subfolder of my default task folder.)
      Sub TestRunScriptMacro()
      Dim objApp As Outlook.Application
      Dim objItem As MailItem
      Set objApp = Application
      Set objItem = objApp.ActiveExplorer.Selection.Item(1)

      'macro name you want to run goes here
      ConvertMailtoTask objItem

      End Sub

      Reply
      • Ankit says

        April 16, 2018 at 8:17 am

        I have made the changes and code looks like below. Instead of 'add' function, I used CreateItem.

        Sub ConvertMailtoTask(Item As Outlook.MailItem)
        Dim objTask As Outlook.TaskItem
        'Set objTask = Application.CreateItem(olTaskItem)
        Set SPSFolder = Session.GetDefaultFolder(olFolderTasks).Folders("Action Item Tracker")
        Set objTask = SPSFolder.Items.CreateItem(olTaskItem)

        With objTask
        .subject = Item.subject
        .StartDate = Item.ReceivedTime
        .Body = Item.Body
        .Save
        .Display
        End With
        Set objTask = Nothing
        End Sub

        Also, my folder is a sub folder of default folder "My Tasks". Please suggest if I am doing something incorrect.

      • Diane Poremsky says

        April 16, 2018 at 2:33 pm

        This is the proper way to identify a subfolder of the default folder:
        Set SPSFolder = Session.GetDefaultFolder(olFolderTasks).Folders("Action Item Tracker")

        The macro works fine here - you need to use items.add
        Set objTask = SPSFolder.Items.Add(olTaskItem)

        and select an email message - it has to be email, not a meeting request, report etc.

        in the VBA editor, go to Tools, options, General tab - is break on all errors selected?
        If you test it using the stub macro i posted easier, does it work?

  24. Ankit says

    April 6, 2018 at 2:25 am

    Hi Team, I am new to VB scripting. Based on your article, I have written below code. Not sure why it is still not working. Can you please check -

    Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim objTask As Outlook.TaskItem
    'Set objTask = Application.CreateItem(olTaskItem)
    Set SPSFolder = Session.GetDefaultFolder(olFolderTasks).Folders("Action_Item_Tracker")
    Set objTask = SPSFolder.Items.Add(olTaskItem)

    With objTask
    .subject = Item.subject
    .StartDate = Item.ReceivedTime
    .Body = Item.Body
    .Save
    End With
    Set objTask = Nothing
    End Sub

    Reply
    • Diane Poremsky says

      April 6, 2018 at 9:46 am

      Any error messages?

      Reply
      • Ankit says

        April 11, 2018 at 1:51 am

        Diane, no error message displayed. It's just the code is not working.

  25. Thomas says

    July 24, 2017 at 1:28 pm

    I modified your code above to work for my needs but I am having an issue.

    My changes:
    Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim objTask As Outlook.TaskItem

    If InStr(Item.Subject, "RE:") Or InStr(Item.Subject, "FE:") Or InStr(Item.Subject, "Updated") Then

    Dim strNada As String
    strNada = ""

    Else

    Set objTask = Application.CreateItem(olTaskItem)

    With objTask
    .Subject = Replace(Item.Subject, "[UMS] ", "")
    .Subject = Left(.Subject, InStr(.Subject, ")"))
    Dim strLDay As String
    strLDay = Trim(Replace(Right(Item.Body, (Len(Item.Body) - InStr(Item.Body, ":"))), ".", ""))
    .Subject = .Subject + " - " + strLDay
    .StartDate = strLDay
    '.StartDate = Item.ReceivedTime
    .Body = Item.Body
    .Save
    End With
    End If
    Set objTask = Nothing
    End Sub

    I already had a rule moving some emails to a folder based on certain criteria so I just edited that rule to also apply this script.

    Your code worked as is with no issues, my code works but not when i get an email from the System sending it.
    I wrote a powershell script to send myself an email with the exact same sender, Subjectm Body and all in the same format. When I run my powershell script and receive the email it works flawlessly but when i get one from the system sending them it doesnt create the task. However if i open my script and type in the exact same info and run it and get a duplicate that one works. Any ideas here?

    Reply
    • Diane Poremsky says

      August 3, 2017 at 12:42 am

      This may not be the cause, but it eliminates one potential issue: Does the rule also do actions? All actions should be in the script - the rule should only have conditions.

      The rule conditions work ok with my simpler macro? That would eliminate something in the message that causes the rule to fail.

      Do you have many messages coming in at once? This can cause rules to fail. You have two options: an itemadd macro or the script in the rule hands off to a macro.
      Sub ConvertMailtoTask(Item As Outlook.MailItem)
      If InStr(Item.Subject, "RE:") Or InStr(Item.Subject, "FE:") Or InStr(Item.Subject, "Updated") Then
      newmacro item
      end if
      end sub

      sub newmacro(Item As Outlook.MailItem)
      'do everything else
      end sub

      Rather than do the subject 3 times:
      .Subject = Replace(Item.Subject, "[UMS] ", "")
      .Subject = Left(.Subject, InStr(.Subject, ")"))
      Dim strLDay As String
      strLDay = Trim(Replace(Right(Item.Body, (Len(Item.Body) - InStr(Item.Body, ":"))), ".", ""))
      .Subject = .Subject + " - " + strLDay

      try
      strSubject = Replace(Item.Subject, "[UMS] ", "")
      .Subject = Left(strSubject, InStr(strSubject, ")")) + " - " + strLDay

      Reply
  26. Stephanie says

    May 3, 2017 at 3:05 pm

    Hi! Thanks so much for the script, it's been immensely helpful. In working with attachments, I have your code up and running and adding the attachments to my tasks. However, it also saves the email as an attachment, and when you open that up, the attachments are obviously there. So that essentially means they are coped twice, and taking up more space. Is there a way to copy only the ‘true’ attachments and not have the email saved as one?

    Reply
    • Diane Poremsky says

      May 6, 2017 at 12:36 am

      Is this line in your code?
      newAttachment.Add Item, olEmbeddeditem

      delete it.

      Reply
  27. Alex Mak says

    April 29, 2017 at 1:03 pm

    Hi Diana,

    I'm a beginner at VBA, looking adopt your code but require the Start Date to change into date specified in the email body . I'm not sure how to recognize the dates titled "Start Date "

    Your help is appreciated.

    Reply
    • Diane Poremsky says

      May 1, 2017 at 12:23 am

      You can do it, but need to pick the date up using regex. You'll need to use a pattern that matches the text in the body. https://www.slipstick.com/developer/code-samples/create-appointment-email-automatically/ shows how.

      Reply
  28. Alex says

    April 29, 2017 at 12:29 pm

    If I need to dynamically accept a different start date as stated in the message body. How should the codes be changed?

    Reply
    • Diane Poremsky says

      May 1, 2017 at 12:14 am

      if the date is in the body, you need to use regex (or instr and mid functions) to grab it.The second macro at https://www.slipstick.com/developer/code-samples/create-appointment-email-automatically/ shows how to get values from the body.

      Reply
  29. Alex says

    March 30, 2017 at 2:49 pm

    Hello Diane,
    it's a great publication!

    May i kindly ask for help with pointing new item to non default folder.
    In this case i have not use string - Set objTask = Application.CreateItem(olTaskItem)
    but as understand have to use
    Set objTask = objFolder.Items.Add(olTaskItem)
    and something like:
    Set objFolder = olNs.GetDefaultFolder(olFolderTasks).Folders("TaskFolderName")

    but can't get success with it

    Please show how it can be done?

    Thank you very much in advance!
    Alex

    Reply
    • Diane Poremsky says

      March 30, 2017 at 5:14 pm

      is the task folder a subfolder of your default tasks? if so, then this will work:
      Set objFolder = olNs.GetDefaultFolder(olFolderTasks).Folders("TaskFolderName")
      if it's somewhere else, you need to use different code, depending on where it is. https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/ has information for other locations.
      once you get the path right, then items.add should work.

      Reply
  30. Jahel Vella says

    January 28, 2017 at 10:26 am

    Hi I have tried the above script in Outlook 2013 and it works perfectly.
    I then tried it on an Outlook 2016 but doesn't work. The rule is working but not the script. This is the script i am using

    Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim objTask As Outlook.TaskItem
    Set objTask = Application.CreateItem(olTaskItem)
    With objTask
    .Subject = "Search confirmation"
    .StartDate = Item.ReceivedTime
    .DueDate = Item.ReceivedTime + 88
    .Body = Item.Body
    .Save
    End With
    Set objTask = Nothing
    End Sub

    Reply
    • John Carlos says

      August 2, 2017 at 3:40 pm

      Please your help, I have same issue, script is not working on outlook 2016, any tip on what can be missing? or how to test what is not working.

      Reply
      • Diane Poremsky says

        August 3, 2017 at 12:47 am

        Add msgbox "Running" as the first line (after the macro name line). Does the message box come up when a message arrives meeting the condition in the rule?

        Is run a script option missing or was macro security changed?
        Run a script missing: https://www.slipstick.com/outlook/rules/outlook-2016-run-a-script-rules/

  31. Mist says

    January 19, 2017 at 3:46 pm

    I am having issues with this. I added the If -> Then string for the new attachments in right after the .body and before .save. Not sure what I am doing wrong here.

    Can you please take a look?

    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
    If Item.Attachments.Count > 0 Then
    CopyAttachments Item, objTask
    End If
    .Save
    End With
    Set objTask = Nothing
    End Sub

    Reply
    • Diane Poremsky says

      January 19, 2017 at 4:04 pm

      What happens when you use it? If you lose the message body, put the if line ahead of the body line.

      Reply
      • Mist says

        January 19, 2017 at 4:42 pm

        No it works as intended. What I am trying to do is include any attachments that was sent in the email to the task being created as well.

      • Diane Poremsky says

        January 19, 2017 at 5:09 pm

        Ah. Did you get the CopyAttachments(objSourceItem, objTargetItem) sub to save the attachments off the message? This part of the macro gets them off the message and adds the to the task

        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

        If Item.Attachments.Count > 0 Then
        CopyAttachments Item, objTask
        End If
        to add it to the tasks.

      • Mist says

        January 20, 2017 at 9:01 am

        Good Morning Diane,

        I am trying to add the code that you have put in the message but for some reason it looks completely different the rest of the code. I think that I am typing it up incorrectly. Is there any way that you can send me something that I can copy and paste into VBA? Basically what I need is the code at the top of this page plus the code that you put in the above message.

        Thank You in Advance!!!!!!!! :D

      • Diane Poremsky says

        January 20, 2017 at 10:41 am

        Copy & paste, don't type.. :) paste the copyattachments sub (I also added it to the article, in the section that tells how to get attachments) after the first macro.

        Add the if/end if lines right before the .save in the first macro.

        (I'm out of the office today and won't be able to post a full working macro until I get back.)

      • Mist says

        January 20, 2017 at 9:04 am

        I would also like to know if this code would work in outlook 2013 and 2010 as well.

        Thanks

      • Diane Poremsky says

        January 20, 2017 at 10:34 am

        Yes, it will. It should work back to at least 2003.

      • Mist says

        January 19, 2017 at 4:48 pm

        This is the orginal code that I have from this website:
        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

        I am trying to add the code for the attachments to it. I need it to include any attachments that came with the email to the task being created. Ahhh this reminds me of school. Whats funny is that I am a network admin but I cant code to save my life. Only know the basics :D

        Also Thanks in advanced Diane.

  32. Al Ameen says

    November 7, 2016 at 11:57 am

    Diane,

    Thank you for the incredibly helpful tutorial. This rule has been incredibly helpful in optimizing my work flow. Currently, the rule that I run creates a task and categorizes that task based on a "keyword" using the subject line of the email. The task includes any attachments in the email. I would like to further improve the rule by creating a calendar appointment X days from the date the email was received. The value of X depends on a "keyword" in the subject line. How would you recommend incorporating this into my rule? I have attached my current code. Thanks much for your help.

    Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim objTask As Outlook.TaskItem
    Dim strCat As String
    Dim arrSubject As Variant
    Dim arrCat As Variant
    With objTask
    .Subject = Item.Subject
    .StartDate = Item.ReceivedTime
    .Body = Item.Body
    If Item.Attachments.Count > 0 Then
    CopyAttachments Item, objTask
    End If

    arrSubject = Array("client1", "client2", "client3")
    arrCat = Array("client1", "client2", "client3)

    For i = LBound(arrSubject) To UBound(arrSubject)
    If InStr(LCase(Item.Subject), arrSubject(i)) Then strCat = arrCat(i)
    Next i
    objTask.Categories = strCat
    .Save
    End With
    Set objTask = 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

    Reply
    • Diane Poremsky says

      January 19, 2017 at 4:02 pm

      Sorry I missed this before.
      Assuming the keyword in the subject is the same that triggers the date offset, all you would need to do is add another array -
      arrDate = Array("3", "5", "7")

      and
      .Start = Item.ReceivedTime + arrDate

      Reply
  33. Kelvin Hux says

    October 26, 2016 at 11:05 am

    Diane,
    This will definitely transform a few departments in my organizations task management. Is there any way to make sure the messages that get converted to tasks are marked as unread? The script I copied works very well in fact almost too well! I'm concerned that some messages are marked as read then in the other rules that put them in folders I don't see them as clearly.

    Reply
    • Diane Poremsky says

      October 26, 2016 at 11:10 am

      add item.unread = true before end sub to make sure they are unread. (You shouldn't need item.save to save the unread state.)

      Reply
      • Kelvin Hux says

        October 27, 2016 at 11:22 am

        Thanks that seemed to work! i will keep working to get more end users comfortable with the MYN system. The next step is to try to get the tasks auto-assigned and/or categorized based on keywords.

      • Kelvin Hux says

        October 27, 2016 at 1:32 pm

        Hi Diane,
        I am not sure what I'm doing wrong here Please help make the messages be marked unread.
        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
        Dim newAttachment As Outlook.Attachments

        Set newAttachment = objTask.Attachments
        newAttachment.Add Item, olEmbeddeditem
        .Save
        End With
        Set objTask = Nothing

        objTask.StartDate = Item.ReceivedTime + 2
        objTask.DueDate = Item.ReceivedTime + 3
        objTask.Categories = "test"
        Item.unread = True

        End Sub

      • Diane Poremsky says

        October 27, 2016 at 2:14 pm

        first, you set the task object to be nothing but then try to use it to set the dates and category. That needs moved up into the with objTask loop. Item.unread is find where it is, but it's usually recommended to have the 'nothing' lines at the very end. You might need to save the item after changing the read state.

        With objTask
        .Subject = Item.Subject
        .StartDate = Item.ReceivedTime + 2
        .DueDate = Item.ReceivedTime + 3
        .Categories = "test"
        .Body = Item.Body

        Dim newAttachment As Outlook.Attachments
        Set newAttachment = objTask.Attachments
        newAttachment.Add Item, olEmbeddeditem
        .Save
        End With

        Item.unread = True
        ' item.save
        Set objTask = Nothing

  34. Wynand Becker says

    September 12, 2016 at 2:30 am

    Diane,

    Brilliant article thank you! Is there a way to auto-assign these to whoever was in the Recipient (or CC) field of the email?

    Reply
    • Diane Poremsky says

      September 13, 2016 at 12:46 am

      Yes, you just need to grab that address
      At the most basic, it's simply
      .Recipients.Add item.cc
      or
      .Recipients.Add item.to

      Reply
  35. Tim says

    September 1, 2016 at 5:24 pm

    Hi Diane, thanks for the great tutorial!

    I regularly receive emails that have two sets of dates in them. The dates are always on two different lines. Is it possible to have the macro recognize the later of the two dates and create a task based on that date?

    Reply
    • Diane Poremsky says

      September 1, 2016 at 6:18 pm

      Yes, using regex in a macro
      https://www.slipstick.com/developer/regex-parse-message-text/ has a sample -
      .Global = True in the pattern should get the last match.

      Reply
      • Tim says

        September 2, 2016 at 11:15 am

        Thanks Diane. I forgot to mention that before the dates mentioned, the email either says "start date:" or "end date:" so I was able to put that into the .pattern section of the script so that it recognizes the correct date.

        But I'm not sure how to combine the RegEx and the Email to Task scripts. Can you provide some guidance on that? Thank you!

      • Diane Poremsky says

        October 26, 2016 at 11:12 am

        You'll use a variable to hold the results of the pattern match then use the variable in the start date:
        .StartDate = msgDate

        if the date format is not one outlook detects, you'll need to format the string, but outlook picks up on a lot of common formats, so it should work.

  36. Taher says

    August 15, 2016 at 3:16 pm

    Hi Diane , i use your code to convert email to Default tasks folder and it works fine , but i am beginer and can't convert it to another Task lis in my sit , so i use this code : Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim objTask As Outlook.TaskItem
    Set SPSFolder = GetFolderPath("SharePoint Lists\taher_test - Accounting Task")
    Set objTask = SPSFolder.Items.Add(olTaskItem)
    With objTask
    .Subject = Item.Subject
    .StartDate = Item.ReceivedTime
    .Body = Item.Body
    .Save
    End With
    Set objTask = Nothing
    End Sub
    what is wrong ?

    Reply
    • Diane Poremsky says

      August 17, 2016 at 1:13 am

      is the task list a subfolder of task folder, in the same mailbox as your default task folder or in another task folder? The answer is what determines the correct value for this:
      Set SPSFolder = GetFolderPath("SharePoint Lists\taher_test - Accounting Task")

      Reply
  37. Joe says

    August 7, 2016 at 9:35 pm

    Hi Diane,

    This is great. I have worked it out so that the selected email message will be sent to my sharepoint task list, adding the body and the attachments. Is there a way to have the window pop up so I can add details to it before it is saved?

    Thanks!

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

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

    Set SPSFolder = GetFolderPath("SharePoint Lists\Meat & Seafood Merchandising Team Site - Team Planner")
    Set objTask = SPSFolder.Items.Add(olTaskItem)
    objTask.Body = objMail.Body
    objTask.Subject = objMail.Subject
    If objMail.Attachments.Count > 0 Then
    CopyAttachments objMail, objTask
    End If
    objTask.Save

    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

    Reply
    • Diane Poremsky says

      August 7, 2016 at 11:03 pm

      you'll add an inputbox - i'd add it before set objTask then insert the string in the field - this will add it at the top of the body, strComment = InputBox("Add your comments")
      Set objTask = SPSFolder.Items.Add(olTaskItem)
      objTask.Body = strComment & vbCrLf & objMail.Body

      BTW, if the body is html and losing it's format, see the macro in the Save Message as Appointment section of https://www.slipstick.com/developer/code-samples/create-outlook-appointment-from-message/. It uses Word code to copy the body to the clipboard and paste it into the message.
      Use this to move the cursor to the top and insert the text.
      objSel.GoTo What:=wdGoToSection, Which:=wdGoToFirst
      objSel.InsertAfter vbNewLine
      objSel.InsertBefore strComment

      Reply
      • Joe says

        August 14, 2016 at 1:32 pm

        Thanks Diane! Is there a way to make the full pop up window open so I can assign to someone, set the due date, add notes, etc.? Thanks again!

      • Diane Poremsky says

        August 14, 2016 at 2:01 pm

        Sure, change .Save to .display (or add .display right before or after .Save)

  38. Alaa says

    June 26, 2016 at 2:32 pm

    hi Diane , i really appreciate your efforts and support
    regarding task from an email using a Rule , can i set another task (SharePoint task) instead the default task

    Reply
    • Diane Poremsky says

      July 5, 2016 at 1:47 am

      Yes, see the Save to a different tasks folder section. It's just a matter of setting the tasks folder and either using items.Add or move to get the task into the folder.

      Reply
      • Alaa says

        August 23, 2016 at 12:44 pm

        Thank you for you reply but unfortunately i can't proceed the provided steps as i'm not familiar with codes.

        how can i set the SharePoint task to be as default
        or even to copy the task created from the individual task to be copied ob the SharePoint task

        my case details:
        Task Name: Cloud Support Team Site - Floor Task
        Location: \\SharePoint Lists

      • Diane Poremsky says

        October 26, 2016 at 11:34 am

        You need this function: https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/#GetFolderPath

        and will use to create the task in the sharepoint folder - first set the folder to a variable, then Add a task to it.
        Set SPSFolder = GetFolderPath("SharePoint Lists\your folder name")
        Set objTask = SPSFolder.Items.Add(olTaskItem)

  39. AAP says

    June 23, 2016 at 3:48 pm

    This is great, thank you. Just one thing that would help me: Is there a way to have the task created with no due date? Thanks in advance!

    Reply
    • Diane Poremsky says

      June 24, 2016 at 12:18 am

      Sure, remove the .startdate and .duedate lines, if present in the code.

      Reply
  40. Haim Moshe says

    May 19, 2016 at 6:03 am

    Hello Diana;
    Thank you for the huge support here to all.
    I need to to be able and mark a sentence withing an email body (which includes an action point) and by clicking a button to create a task from it in which subject or body is the marked sentence

    Reply
    • Diane Poremsky says

      May 19, 2016 at 10:54 am

      This macro - ConvertSelectionToTask creates a task from selected text in an incoming email. Message subject = task subject, selection = task body. As written, it works with the reading pane but can be changed to work with either open or selected messages.

      Reply
  41. MUGAHID M FARAJ says

    May 4, 2016 at 10:06 am

    Hi Diane,
    Am trying to caret a project on outlook by macro by(Design a form ) with using Rule script on outlook, but So I need to caret new form design by outlook developer to make it on outlook task (TO, notification, Tracing process(who was made the Update ) ) , So when I make new Task on outlook it require that item:-

    1.To: from Exchange I have selected .
    new label not include it on the task like when you send email you have to select the recipient .
    2-Notification : Reminder the user from the owner .
    Reminder the user about delay the task or receive new update from the task user/ owner.
    3.Tracing: Update the task by the users which assign to them by the owner .
    So the Owner can Tracing the user n1 or n2 or n3 who made the last update .

    Please help me on my project.
    thank and best regards.

    Reply
    • Diane Poremsky says

      May 12, 2016 at 12:07 am

      i'll need to think on this one, it fairly complicated.

      Reply
  42. Martin Rene Rasmussen says

    April 26, 2016 at 2:14 pm

    Hey Diane, Im trying to get the script to move the email from "IT dept." mailbox, to IT dept." tasks, but it moves it to my private tasks. (the "IT dept." is a secondary mailbox that I have add, is it possible to move it to the tasks folder of the "IT dept."
    And if so, how :)

    Thank you in advance.

    Reply
    • Diane Poremsky says

      April 30, 2016 at 12:25 am

      it is possible. You can either move the task after creating it or using items.add to add it to the folder when its created. This macro shows how to do it for appointments - https://www.slipstick.com/developer/copy-new-appointments-to-another-calendar-using-vba/ - the method is the same for tasks.

      Reply
  43. Esther Perron says

    April 21, 2016 at 1:40 pm

    Hi Diane,
    I used your instructions and it worked perfectly. To convert into a Task request, is there a way to not have someone assigned so you can assign to various people once the emails are converted to a task request .

    Reply
    • Diane Poremsky says

      April 30, 2016 at 12:43 am

      Remove the recipients.add line and change .send to .display - this will keep it up on screen so you can enter an address and send it.

      Reply
  44. Joshua says

    April 18, 2016 at 10:46 am

    Diane,

    Can you tell me a way to create a pop-up window (or similar) asking if I want to create a task? I often create a "waiting on reply" task for sent email; however, not always. It would be handy to use this script for sent emails with the pop-up every time I send an email.

    Thank you for this wonderful post and your time.

    Respectfully, Joshua

    Reply
    • Diane Poremsky says

      April 30, 2016 at 12:45 am

      There is a flag sent messages macro at https://www.slipstick.com/developer/code-samples/set-flag-follow-up-using-vba/ that does this.

      Reply
  45. Davd says

    March 28, 2016 at 5:14 am

    This is amazing! One quick question. I use the below script when I click the macro button in the ribbon. How do I add a category or flag the email so that I know the macro has been used on it and so that I know this email is in my task list?

    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
    .Categories = "%Outlook-Toodledo"
    'Add the message as an attachment
    .Attachments.Add objMail
    .Save
    End With

    Set objTask = Nothing
    Set objMail = Nothing
    End Sub

    Reply
    • Diane Poremsky says

      March 29, 2016 at 1:41 am

      After End With line, add
      objMail.Categories = "Added to Tasks" & objMail.Categories
      if it doesn't seem to work, add another line: objmail.save

      Reply
  46. Andrew says

    March 17, 2016 at 1:12 pm

    Diane,

    I am working with Outlook 13 on my pc at work. I have been playing around with the scripts to convert email into task. I get the script saved inside the vba and created rule inside Outlook. I set it up that when I flag the email it moves to a task. But, I noticed this isn't happening and its just treating it as a flagged email inside Outlook Tasks.

    Can you offer some guidance?

    Reply
    • Diane Poremsky says

      March 17, 2016 at 3:10 pm

      Do you have macro security set to low? Did you restart Outlook?

      Reply
  47. LAM says

    March 2, 2016 at 11:04 am

    Hi Diane.
    I receive request for bids from a number on contractors via email. I wanted to set up something to take the company, job name and bid due date and add to a calendar. Is there a way to do that?

    Reply
    • Diane Poremsky says

      March 2, 2016 at 11:31 pm

      These values are in defined fields within the email? If so, you can use regex to grab the values and put them into the event.
      There are regex examples here - https://www.slipstick.com/developer/regex-parse-message-text/

      Reply
  48. Soran says

    February 9, 2016 at 8:29 am

    thanks for the script it is really helpful, I am using it yet i have one issue, and it is related to scripts in general so my questions are following:
    1) how to save the scripts? i did hit the save button nothing happens, however if i shut down outlook it asks me to save the project <- and here is the problem
    2) once outlook starts again the scripts won't run any more.

    I did some search and I found one way to over come it and by deleting the project vba file VbaProject.OTM (which means i have to do copy/paste code every time i start outlook (as i don't save the vba project file anymore)

    question 3) is there any other way when saving the vba file will be reused..

    Reply
    • Diane Poremsky says

      March 2, 2016 at 11:28 pm

      1. Save should work. But if you forget, outlook reminds you when it closes.
      2. They should still work unless the macro security changed.
      Are you signing the macros with selfcert? If so, remove the cert and set security to low - see if it works when you restart outlook.

      Reply
  49. Mac says

    February 4, 2016 at 3:02 pm

    Hi Diane, firstly I'd like to say thanks for this script. I've been using it for a while now and it works perfectly for my needs, but now I would like to enhance it by replacing the subject of the task with a row from the original mail body called description, and also populate some custom fields within my custom task form, also from the message body for example reported by and ID.

    I started by trying to extend the code by following your regex-parse-message-text and run-script-rule-change-subject-message tutorials but I don't seem to be able to get them work at all...

    Do you happen to have any examples where both the email to task script and parsing and writing to the subject or custom form fields work in one script?

    Your advice would be greatly appreciated :)

    Reply
    • Diane Poremsky says

      March 2, 2016 at 11:25 pm

      you'll definitely want the regex method on this page - https://www.slipstick.com/developer/regex-parse-message-text/ - to get the description field.

      working with custom fields isn't hard - you need to use userproperties.add
      Dim objProp As Outlook.UserProperty
      Set objProp = obj.UserProperties.Add("fieldname", olText, True)
      objProp.Value = YourValue

      list of all property types (olText in the code): https://msdn.microsoft.com/en-us/library/office/ff862452.aspx
      true/false - True if the property will be added as a custom field to the folder that the item is in. This field can be displayed in the folder's view. False if the property will be added as a custom field to the item but not to the folder. The default value is True.

      Reply
  50. Curt Faulk says

    February 3, 2016 at 3:44 pm

    Hi, Diane. I've been using this script with *great* success for nearly two years. Back then (March 2014), you even helped me customize it a bit.

    Now I'm trying to determine if I can preserve the format of the email message body text when the task is created.

    What is happening when the script runs now is that the text is changed to plain text and often extra blank lines are added in the body text, such as between lines in an email signature and between email body paragraphs. (Sort of like in Microsoft Word where a paragraph mark (enter key) is used instead of SHIFT-ENTER.)

    Reply
    • Diane Poremsky says

      February 3, 2016 at 11:40 pm

      Tasks only support RTF formatting at this time. You could copy the email as an attachment so you have a readable version. Depending on the message format, you might be able to use the VBA replace function to remove extra lines, but I haven't tried it.

      Reply
      • Diane Poremsky says

        February 3, 2016 at 11:44 pm

        Well, what do you know... it worked. :)
        This removed the extra line breaks in the handful of messages I tested it on -
        .Body = Replace(objMail.Body, vbCrLf & vbCrLf, vbCrLf)

      • Curt Faulk says

        February 4, 2016 at 11:02 am

        OK, that works, but it strips the "From" "Sent" "To" "Subject" info from the email. How can I change my script so that "From" "Sent" "To" "Subject" is retained?

        The .Body in my script currently looks like this: .Body = "From: " & objMail.Sender & vbCrLf & "Sent: " & objMail.ReceivedTime & vbCrLf & "To: " & objMail.To & vbCrLf & "Subject: " & objMail.Subject & vbCrLf & " ------------------------------------------ " & vbCrLf & objMail.Body

        Thanks again, so very much.

      • Diane Poremsky says

        February 29, 2016 at 9:39 am

        I thought I answered this before. :(
        Replace only the body segment with the replace function:
        .Body = "From: " & objMail.Sender & vbCrLf & "Sent: " & objMail.ReceivedTime & vbCrLf & "To: " & objMail.To & vbCrLf & "Subject: " & objMail.Subject & vbCrLf & " ------------------------------------------ " & vbCrLf & Replace(objMail.Body, vbCrLf & vbCrLf, vbCrLf)

      • Curt Faulk says

        February 11, 2016 at 10:45 am

        Hi, Diane. I've tried various insertion points of the replace function as shown above. It definitely works, just as you say. I'd really like to retain the message sender/date/time/subject info that I'm getting now, but I just can't make the replace function work without losing that info. My script without the replace function currently looks like this:

        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"
        .Save
        End With

        Next
        Set objTask = Nothing
        Set objMail = Nothing
        End Sub

      • Diane Poremsky says

        February 11, 2016 at 11:52 pm

        Replace the last objmail.body:
        .Body = "From: " & objMail.Sender & vbCrLf & "Sent: " & objMail.ReceivedTime & vbCrLf & "To: " & objMail.To & vbCrLf & "Subject: " & objMail.Subject & vbCrLf & " ------------------------------------------ " & vbCrLf & Replace(objMail.Body, vbCrLf & vbCrLf, vbCrLf)

      • Curt Faulk says

        February 29, 2016 at 9:31 am

        Perfect. As usual, you have been exceedingly helpful.

  51. Ryan says

    January 26, 2016 at 5:13 am

    Hi, I have created the script, created the rule and associated the macro to the rule, and enabled macros in trust centre, but no task is created. I only have the default "Tasks" folder. Any ideas what I may have missed?

    Reply
    • Diane Poremsky says

      February 3, 2016 at 11:50 pm

      Did you check the macro security level and restart Outlook?

      Test the last macro on the page that runs on a selected message - does it work?

      Reply
  52. Bill Moore says

    January 4, 2016 at 8:17 am

    I have a quick step created that simply creates a task with attachment and then moves the Email to a folder (e.g., 2016-All Emails).. I am trying to create a macro that I can add to the QAT to essentially do that same thing. I have tried to work with this macro as a basis but cannot seem to get it to workout. The rational behind having the entire email attached to a task is so that I can open up and have any attachments that were provided and also reply with the original email... Any help would be much appreciated..

    Reply
    • Diane Poremsky says

      February 4, 2016 at 12:17 am

      What isn't working? The last macro (Create Task from the selected message) should work perfectly. Add .Attachments.Add objMail inside the with task / end with lines.

      Reply
  53. Alex says

    December 30, 2015 at 3:50 pm

    I've been using for years productivity rules that create a task or an appointment out of an email message. First hassle came when switching to an Exchange Active Sync account, when newly created tasks or appointments no longer allowed attachments. Learned to live with that. As of 2 weeks ago, I can no longer create "create an appointment with text of message" from my gmail account (can still do it from my outlook.com account). Error message popup is "Calendar folder cannot be found".
    Any solution or workaround? I've already followed Google's recommendation to allow access to less secure apps at "Account settings: Your browser is not supported"
    Thanks!

    Reply
    • Diane Poremsky says

      February 4, 2016 at 12:19 am

      Di you change your configuration? What calendar folder is it trying to use? Unless you added code to change the folder, it should use the default calendar.

      Reply
  54. Brent Jones says

    December 21, 2015 at 7:26 pm

    Hi there, great code and have added to it a bit, i was wondering if there is a way to setup multiple tasks from the one email i.e. where i work we get global amendments that are for multiple days sat/sun/mon where that department are away for the weekend while my department is on station. we get the email from them to change commercial (i work in TV) and is important that we do this for the days requested. Is there a way to create a task for each day? if i can, in the body of the email have them state the start date and end date it will create the three tasks for the days outlined in the body?

    Reply
    • Diane Poremsky says

      December 21, 2015 at 11:30 pm

      You could use a macro to grab data from the body and create tasks but the data needs to be clearly defined so regex can find it. This shows how to use regex - https://www.slipstick.com/developer/regex-parse-message-text/

      Reply
  55. Luis says

    November 23, 2015 at 11:28 am

    Hello Diane:
    I have followed the suggestion you offered to have all attachments from the messages copied to the task I copied
    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
    To the end of the macro you provided and add the lines you mentioned before the .save
    But the code does not run I a get an error of ambiguous name detected: CopyAttachments.
    The entire code looks like the following. what is wrong?
    Please help. thank you

    Sub ConvertMailtoTask()
    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 + 7
    .Body = objMail.Body
    If Item.Attachments.Count > 0 Then
    CopyAttachments Item, objTask
    End If
    .Save
    End With

    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

    Reply
    • Diane Poremsky says

      November 23, 2015 at 2:39 pm

      This error: ambiguous name detected: CopyAttachments means you have the copyattachments macro in twice. If you are using it with another macro, you only need to add it once - all macros can use it. so... try deleting it and see if the macro works.

      Reply
      • Luis says

        November 24, 2015 at 5:07 am

        Hi Dianne,
        Sorry to bother you again,
        I redid the code, first I copied and past the following
        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
        It works ok it creates the task, but it does not copy the attachment, then I followed your advice and copied the CopyAttachments function to the end of the macro, this is what looked like.
        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
        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
        IT WORKED BUT STILL NO ATTACHMENTS, THEN I FOLLOWED YOUR OTHER INSTRUCTION AND COPIED
        If Item.Attachments.Count > 0 Then
        CopyAttachments Item, objTask
        End If
        before the .save as you said. But now I get a Run Time “424” Object required.
        Obviously I am doing something wrong. Can you help me?
        Many thanks.

      • Diane Poremsky says

        November 24, 2015 at 10:29 am

        Item refers to the object that has attachments but you aren't using item to refer to the object, you are using objMail - so change item to objMail and it should work.
        If Item.Attachments.Count > 0 Then
        CopyAttachments Item, objTask
        End If

  56. Jake says

    November 4, 2015 at 12:38 pm

    Diane:

    This is great! I copied the basic language and am now creating a task for certain emails. Where I'm getting hung up is adding the task to a specific folder. I use Wunderlist and have their Outlook add-on. I have a specific folder I would like to create the task in called "Work - Truck Times". Basically, I would like to add the task to a Wunderlist folder so that the task will show up on the app's mobile interface.

    I tried to accomplish this with the following script, but I'm missing something because it's not working:

    Sub ConvertMailtoTaskTT(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
    .Categories = "Wunderlist"
    .Save
    End With
    SPSFolder = Session.GetDefaultFolder(olFolderTasks).Parent.Folders("Work - Truck Times")
    Set objTask = Application.CreateItem(olTaskItem)
    .Save
    End Sub

    Where am I going wrong?

    Reply
    • Diane Poremsky says

      November 4, 2015 at 1:30 pm

      This uses the default task folder: Set objTask = Application.CreateItem(olTaskItem) you either need to move it after you save it - objTask Move spsfolder or set the folder first and add the new task.
      Set objTask = spsfolder.Add(oltaskItem)

      Reply
      • Mike says

        April 29, 2016 at 3:26 pm

        This code works GREAT! Thank you!
        If I want to automatically move the task to a different task folder ex: thatTaskFolder, what would the code be?

      • Diane Poremsky says

        April 30, 2016 at 12:12 am

        Replace this line
        Set objTask = Application.CreateItem(olTaskItem)

        with these - this moves it to a subfolder of tasks.
        Set folContacts = Application.GetDefaultFolder(olFolderContacts)
        Set folContacts = folContacts.folder("foldername")
        Set objTask = folContacts.items.Add(olContactItem)

        more information on using non-default folders is here - https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/

  57. Simon Spence says

    October 13, 2015 at 10:45 am

    in GTDOA when creating an email there is an option on the email Ribbon that allows the sender to 'Send and Action'. i then send the email and am presented with a box that enables me to custom the task and add 'project/sub project' details, this then further populates an Outlook Task with the email that i am sending which i can then further custom with due dates and alarms etc. it sounds a phaf but actually is very quick and easy. All this said, all i want is the option to send an email and for that sent email to be attached/linked to a task box.

    Reply
    • Diane Poremsky says

      October 14, 2015 at 11:30 am

      That would be easy enough to do using a macro. A sample basic macro is here - https://onedrive.live.com/redir?resid=92BFE835F50A11F5!904487&authkey=!AGdJC5ejvvYDOm4&ithint=folder%2ctxt - create a button for te create task macro and click it before sending the message. a new task form opens after the message is sent. it works best if you use send immediately, so the correct message is identified as the one to convert to a task.

      Reply
  58. Simon Spence says

    October 13, 2015 at 7:58 am

    Hi Di,

    Why oh why dont MS add the functionality to create a task if required on sending an email. This is seemingly so simple and would be such a valuable function. I've loved using GTDOA but they have stopped supporting the add-in. I just want to be more effective in my work!! simple things like sub tasks and creating a task from an email on sending would be marvelous. i worry that using script will clutter the subject bar and confuse the recipient??

    what do you think?

    Reply
    • Webmaster says

      October 13, 2015 at 9:22 am

      You can use a script without adding to the message subject. How did the gtd addin work? We can probably replicate the behavior with code, or at least some of it.

      Reply
  59. Thibaud says

    July 8, 2015 at 5:38 am

    Hi Diane,

    Thanks a lot for your explanation !
    I got a problem with the .Recipients.Add "alias". It's doesn't workm VBA told me "Application-defined or method-defined error". My code :

    Sub Create_Task(study As String, deadline As Date)

    Dim OutApp As Object
    Dim OutTask As Object
    Dim strbody As String
    Dim sponsors As String
    requester = Worksheets("control_vocabulary").Range("A1").Value
    Set OutApp = CreateObject("Outlook.Application")
    Set OutTask = OutApp.CreateItem(olTaskItem)

    ligne_users = 5
    colonne_Study = Worksheets("Sponsors").Cells.Find(What:=study, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Column
    While Worksheets("Sponsors").Cells(ligne_users, colonne_Study).Value ""
    sponsors = sponsors & ";" & Worksheets("Sponsors").Cells(ligne_users, colonne_Study).Value
    ligne_users = ligne_users + 1
    Wend

    With OutTask
    .Assign
    .Subject = study
    .Body = "Deadline pour le test : " & study
    .DueDate = deadline 'échéance
    .ReminderTime = True 'Rappel
    .Display
    .Recipients.Add "alias" ' at the end it's going to be the sponsors variable but firt I need to fix the bug
    .Send
    End With
    End Sub

    Reply
  60. Atasha says

    June 12, 2015 at 4:51 am

    Hi guys,
    I have a similar problem, and can't seem to find a solution.
    When someone is going to a vacation or a business trip, all of the employees receive an email with the name of an employer and starting and ending date he's going to be away.

    I would like for an event to be automatically created in shared calendar using that information.
    It should only show name of the employer, and all day event from said date to date.

    Would it be possible?

    I've also tried to connect outlook to database and access table, but couldn't get anything to work ... except to export table form access, convert it to outlook format, and import ... i would like to skip all that manual work :(

    Thank you.

    Reply
    • Diane Poremsky says

      July 14, 2015 at 8:18 am

      The tough part is doing this if each person maintains there own calendar. If there is a shared calendar, it's much easier to check and generate emails. I have a sample macro that does this at https://www.slipstick.com/developer/send-email-outlook-reminders-fires/ - if the events have reminders, you can trigger it using that reminder, otherwise I'd set a reminder in my calendar (or a task) that would trigger the macro to check the calendar(s). The calendars would need to be open in the outlook that has the macro and that person would need the right permissions to the calendar.

      Reply
  61. mikulthegreat says

    May 27, 2015 at 6:59 pm

    I use a few different computers to access Outlook, and I'm trying to get the rule to run on each of the computers but not repeat itself and create multiple tasks. I created a distribution list that everytime it receives a message it will create a new task. I'm trying to get it to only run once per email.

    Is there an easy way to make it apply to only unread mail items?

    Reply
    • Diane Poremsky says

      May 27, 2015 at 11:21 pm

      At the beginning, you can check the read state:
      if item.unread = true then
      'create task
      .unread= false
      end if.

      Reply
  62. Sumeet says

    March 31, 2015 at 9:27 pm

    Hi Diane
    thanks for this amazing post
    while it has been asked previously in this chain whether the script can run when outlook is offline; is there absolutely no way that they script be stored in the mail server and emails get converted to tasks when one is on the move?
    pls do let know
    thanks
    sumeet

    Reply
    • Diane Poremsky says

      March 31, 2015 at 10:12 pm

      No, sorry, it cannot run on the server.

      Reply
  63. Jatin says

    March 5, 2015 at 6:09 pm

    Hi there,

    What I am trying to do is create an calendar event from mail subject line as below.
    If I receive any mail with subject line as Due Date:01/01/2015 it should create a event in calendar and also alert me whenever that date and time occurs.
    Is this possible by rule or macro? Any help would be much appreciated.

    Thanks,
    Jatin

    Reply
    • Diane Poremsky says

      March 5, 2015 at 8:06 pm

      You can't use a rule by itself, but can use a script with a rule to find messages which might match then process it more with a script. A regex example is here: https://www.slipstick.com/developer/run-a-script-rule-autoreply-using-a-template/

      I didn't test it, but this should be close:

      Sub ConvertMailtoTask(Item As Outlook.MailItem)
      Dim objAppt As Outlook.appointmentItem
      Dim Reg1 As Object
      Dim M1 As Object
      Dim M As Object
      Dim strDate
      Set Reg1 = CreateObject("VBScript.RegExp")

      With Reg1
      .Pattern = "Due Date[:]([\d/]*)"
      End With

      If Reg1.Test(Item.subject) Then

      Set M1 = Reg1.Execute(Item.Body)
      For Each M In M1
      strDate = M.SubMatches(0)
      Next
      End If

      Set objAppt = Application.CreateItem(olappointmentItem)
      With objAppt
      .Subject = Item.Subject
      .StartDate = strdate
      .Body = Item.Body
      .ReminderSet = True
      .ReminderTime = strdate
      .Save
      End With
      Set objappt = Nothing
      End Sub

      Reply
  64. Bennett says

    February 24, 2015 at 4:59 pm

    I would like to move some select parts of the body of the email into standard and custom fields of the task. The body of the email is entirely in the form of a table (Several rows and 2 columns). Is this possible? If so what would the code look like?

    Reply
    • Diane Poremsky says

      March 5, 2015 at 7:34 pm

      if the rows are identifiable and unique, you can use regex to get the values. See https://www.slipstick.com/developer/regex-parse-message-text/ for the basic idea.

      Reply
  65. Jack Coole says

    February 23, 2015 at 6:09 am

    Hi,

    First, Thanks for the tutorial! Was VERY helpful!

    Second. At the moment we are running it by having a generic e-mail address for our IT department which people can e-mail with their problems and issues. When the account receives an e-mail it then runs your script and sends both me and my colleague a task request. The only problem is that when we're filling out the task of where we're up-to, we cannot view the extra information that the other has written into the task because we're not the owner of the task. This means going onto the IT e-mail address and filling it out that way. As sometimes we're unable to do this I was just wondering if there was a way to update the task information without sending a task update which will just send out a new task request, leading to multiple tasks about the same job.

    Do you have any ideas on how it could be run?

    Reply
    • Diane Poremsky says

      March 31, 2015 at 10:12 pm

      Offhand, no, I can't think of a way to do this.

      I worked on a task update macro that looked for specially crafted subjects and processed the messages as task updates. I don't know if something like that would work for you.

      Reply
  66. Alita says

    January 6, 2015 at 2:31 pm

    I am trying to make sure I have the basic email and copy attachment to task code right. Could you please copy it all together for me?

    Reply
  67. Alexis Hernandez says

    November 25, 2014 at 9:35 am

    yes, that's exactly what I need. I tried researching how to format my own codes and cant seem to find how... any suggestions?

    Reply
    • Diane Poremsky says

      November 26, 2014 at 1:13 am

      Because the task wasn't assigned by that person, you can't do it using the automated feature in Tasks, but you could use a macro to send an update message when its marked complete.

      Reply
      • Alexis Hernandez says

        November 26, 2014 at 9:50 am

        Okay. I understand. 2 questions... Is there a code I can use to get the task assigned by the sender so that when I mark it complete the status report gets sent to them? Or would it be best to have the macro send an updated message? We are looking for something to be automatic, preferably to run on a script

      • Diane Poremsky says

        November 26, 2014 at 12:42 pm

        i don't think you can set the task to be from the sender, it would be easier to generate an email. The email can be automatic - it'll look for a task to be marked compete and kick in when that happens.

      • Alexis Hernandez says

        November 26, 2014 at 12:46 pm

        how would I configure that automatic email to be sent out using a macro & rules?

      • Diane Poremsky says

        November 26, 2014 at 1:08 pm

        You could change this to send a reply - https://www.slipstick.com/developer/code-samples/change-category-task-marked-completed/ - you'll need to put the email address in the task, either in the body or in a new user-defined field.
        Code sample to generate an email is here - https://www.slipstick.com/developer/create-a-new-message-using-vba/

      • Diane Poremsky says

        November 26, 2014 at 1:22 pm

        I threw those code samples together to create the sample in this file: send task update

      • Alexis Hernandez says

        November 26, 2014 at 3:33 pm

        I may be very confused at this point.... I took the code sample you made and entered both mine and my supervisors emails, when I ran a test nothing happened. heres the code below.... what am I doing wrong? should the create task go above the create mail item?

        I receive emails with the subject "Incomplete task notification" from Danielle@century21city.net, frontdesk@century21city.com & century21city@att.net. I'd like all of those emails to be turned into tasks upon receipt into my inbox. Then once I mark those tasks complete, I want an automatic email with the original emails subject (so that the message pairs in the inbox under the correct thread) to be sent to Danielle@century21city.net- saying "task completed". how can I turn this into a macro to run a script.

        I hate to ask for so much help, but I've been stuck on this for quite sometime. Can you refer me to a website that will help me build macro codes on my own?

        '** This goes in thisoutlooksession
        Public WithEvents OlItems As Outlook.Items

        Public Sub Initialize_handler()
        Set olItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks).Items
        End Sub

        Private Sub OlItems_ItemChange(ByVal Item As Object)

        If Item.Complete = True And Item.IsRecurring = False Then

        If InStr(1, Item.Categories, "Completed") = False Then

        With Item
        .Categories = "Completed" & .Categories
        .Save
        End With

        Dim objMsg As MailItem
        Set objMsg = Application.CreateItem(olMailItem)
        With objMsg
        .To = Item.UserProperties("danielle@century21city.net")
        .Subject = "This is the subject"
        .BodyFormat = olFormatPlain ' send plain text message
        .Body = "Whatever"
        .Display 'or .send
        End With

        Set objMsg = Nothing

        End If
        End If

        End Sub

        '**** Change script to set a custom field
        Sub ConvertMailtoTask(Item As Outlook.MailItem)
        Dim objTask As Outlook.TaskItem
        Dim objProp As Outlook.UserProperty
        Dim strAddr As String

        strAddr = Item.SenderEmailAddress

        Set objTask = Application.CreateItem(olTaskItem)

        With objTask
        Set objProp = .UserProperties.Add("alexis@century21city.com", olText, True)
        objProp.Value = strAddr
        .Subject = Item.Subject
        .StartDate = Item.ReceivedTime
        .Body = Item.Body
        .Save
        End With
        Set objTask = Nothing
        End Sub

      • Diane Poremsky says

        November 26, 2014 at 5:25 pm

        if all responses will go to one address, it makes it easier - you won't need to set the user property.

        Use this in the sub that sends the 'task is complete' message:
        With objMsg
        .To = "alexis@century21city.com"
        .Subject = Item.Subject 'gets task subject
        .Body = "Task Completed"
        .Display ' use .send to automatically send it
        End With

        and this to create the task - it should be what you used before:
        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

        There aren't many sites that will help you build macros - most expect you to have some knowledge of what you are doing so they aren't necessarily friendly towards beginners. msdn.microsoft.com and outlookcode.com are good resources, outlookforums.com, stackexchange.com and the MSDN forums are good if you have a question.

  68. Alexis Hernandez says

    November 24, 2014 at 1:41 pm

    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.

    Reply
    • Diane Poremsky says

      November 25, 2014 at 12:22 am

      So you want to create a task from an email then send the person who sent you the email a completed status report?

      Reply
  69. Alexis Hernandez says

    November 21, 2014 at 1:05 pm

    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.

    Reply
    • Diane Poremsky says

      November 22, 2014 at 11:21 pm

      That is only available if you create a task request - but yes, it can be set using VBA AFAIK. When you use the following snippet in the macro, it creates a task request and both keep an updated copy and send status report are checked.
      With objTask
      .Assign
      .Recipients.Add "drcp@cdolive.com"
      .Subject = Item.Subject
      .StartDate = Item.ReceivedTime
      .Body = Item.Body
      '.Send
      .Display
      End With

      Reply
  70. Matthew Schwarz says

    October 27, 2014 at 10:22 pm

    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.

    Reply
    • Diane Poremsky says

      November 22, 2014 at 11:32 pm

      Asking for a subject is simple -
      Dim strSubject As String
      strSubject = InputBox("enter new subject")

      then replace the subject = item.subject line with this:
      .Subject = strSubject

      Date pickers are more difficult. It would be easier to ask for a date in an inputbox and pass the value.

      Reply
  71. Thiago says

    October 13, 2014 at 4:04 pm

    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.

    Reply
    • Diane Poremsky says

      October 13, 2014 at 9:08 pm

      Do you want it to automatically create the task? You'll need to use an itemadd macro and watch the sent items folder. You could also use an itemsend macro to create a task after you hit Send but before the item is sent.

      A sample itemsend macro is here - https://www.slipstick.com/developer/code-samples/set-flag-follow-up-using-vba/ - replace the flag close with the new task code.

      Reply
      • Thiago says

        October 14, 2014 at 2:09 pm

        Thanks a lot Diane! I did it successfully!

        Now I will work to manage the different created tasks to avoid duplication of tasks after sending an email.

        I'm aiming to update an associated task instead of creating a new one.

        The code I've developed is:

        Dim WithEvents sentItems As Outlook.Items

        Private Sub Application_Startup()
        Dim ns As Outlook.NameSpace
        Dim fld As Outlook.MAPIFolder
        Set ns = Application.GetNamespace("MAPI")
        Set fld = ns.GetDefaultFolder(olFolderSentMail)
        Set sentItems = fld.Items
        Set fld = Nothing
        Set ns = Nothing
        Dim TextPos As Integer
        Dim TextPosForCco As Integer
        Dim ResponseDays As Integer
        End Sub

        Private Sub sentItems_ItemAdd(ByVal Item As Object)
        ResponseDays = 3

        If Item.Class = olMail Then
        Set objMsg = Item
        Dim objTask As Outlook.TaskItem
        Set objTask = Application.CreateItem(olTaskItem)
        With objTask
        .Subject = Item.Subject
        .Body = Item.Body
        .Categories = "SI's"
        .StartDate = Date
        .DueDate = Date + ResponseDays
        .ReminderTime = Date + ResponseDays
        .ReminderSet = True
        .Save
        End With
        Set objTask = Nothing
        End If
        End If
        End Sub

      • Thiago says

        October 14, 2014 at 5:58 pm

        Hello Diane,

        Sorry to be disturbing you, but I'm not being able to get the current existing tasks inside my Outlook. I'm trying to use, for example:

        Dim fldTasks As Outlook.MAPIFolder
        Dim tasksItems As Outlook.Items
        Set fldTasks = ns.GetDefaultFolder(olFolderTasks)
        Set tasksItems = fldTasks.Items

        I've also tried to use:

        Set fldTasks = ns.GetDefaultFolder(olFolderTasks).Parent.Folders("Tasks")

        But both of these options returned an empty variable, so I cannot loop into the current tasks I have.

        Do you know what can be happening in this case?

        Best Regards

      • Diane Poremsky says

        October 27, 2014 at 11:15 pm

        This won't work: Set fldTasks = ns.GetDefaultFolder(olFolderTasks).Parent.Folders("Tasks")

        you only need Set fldTasks = ns.GetDefaultFolder(olFolderTasks)
        Try changing this: Dim tasksItems As Outlook.taskitem
        if you have a second tasks folder at the same level as the default tasks, you'd use Set fldTasks = ns.GetDefaultFolder(olFolderTasks).parent.folders("foldername")

        Do you have more than one account in the profile? If the tasks is in a different data file, you'll need to get the folder using a different method.

  72. Russ B. says

    September 17, 2014 at 3:33 pm

    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!

    Reply
    • Diane Poremsky says

      September 18, 2014 at 12:06 am

      You'd create a new task and save then insert the attachment - the code should all be on this page, it just needs put together. Attachment code is under the working with attachment section.

      Reply
  73. David Nestlebush says

    September 17, 2014 at 12:10 pm

    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

    Reply
    • Diane Poremsky says

      September 17, 2014 at 3:07 pm

      The attachment lines need to reference the mail object:
      If objMail.Attachments.Count > 0 Then
      CopyAttachments objMail, objTask
      End If

      you also need the mail object on received time - outlook doesn't understand it and makes up a date. :)
      objTask.StartDate = objmail.ReceivedTime

      plain old "Date" or "Time" are VB functions and use the current date or time, the same as Today() or Now().

      Reply
  74. John says

    September 15, 2014 at 10:38 pm

    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

    Reply
    • Diane Poremsky says

      September 15, 2014 at 11:44 pm

      You need to use .Links.Add objContact - you'll need to create the contact it if doesn't exist or resolve it if it does.

      You may need to show the contact linking field too - I know in outlook 2013, you need to set the showcontactfieldobsolete key.

      Reply
      • John says

        September 16, 2014 at 3:20 am

        The Contact linking field is showing (I've enabled it and I'm on 2010).

        Forget about validating that the contact exists and then creating it if not... would you please show me how to add the contact?

      • Diane Poremsky says

        September 16, 2014 at 8:36 am

        You can't just add an address - you need to find the contact. If you use just a name or address, outlook errors with 'item cannot be found'

        objtask.Links.Add objmsg.sender

        if you create the contact -
        Set objContact = Application.CreateItem(olContactItem)
        With objContact
        .FullName = objMsg.Sender
        .Email1Address = objMsg.SenderEmailAddress
        .Save
        End With

        then use

        objtask.Links.Add objContact

        it works. better would be to attempt to resolve the address and create it if outlook can't resolve.

      • John says

        September 16, 2014 at 11:47 pm

        "You can't just add an address - you need to find the contact."

        Diane - thanks for your help so far. Something I didn't state in my original request was that almost 100% of the emails I'm dealing with are from internal personnel, over Exchange. I apologize for not being clear on this.

        So, I guess my clarified requirements are now:

        1. If sender is in Contacts, add contact to objTask.Links

        And then:
        * If sender is not in Contacts, create in Contacts, and then add contact to ObjTask.Links

        Or, even better:
        * If sender is not in Contacts, find sender in Exchange address book, add (create?) to Contacts, and then add contact to ObjTask.Links

      • Diane Poremsky says

        September 17, 2014 at 12:27 am

        If outlook is set to resolve the GAL first, it should work (I think!)... i don't have any code handy though.

      • Diane Poremsky says

        September 17, 2014 at 12:43 am

        this snippet messy but it seems to work ok on contacts - the stuff between the === is the code to add to your code.

        Call CopyFullBody(objMsg, objTask)

        '=====================
        Dim objContacts As Outlook.folder
        Dim objNS As Outlook.NameSpace
        Dim objProperty As Outlook.UserProperty

        Set objNS = Application.GetNamespace("MAPI")
        Set objContacts = objNS.GetDefaultFolder(olFolderContacts)
        Set objContact = objContacts.Items.Find("[email1address] = " & objMsg.SenderEmailAddress)
        If TypeName(objContact) = "Nothing" Then

        Set objContact = Application.CreateItem(olContactItem)

        With objContact
        .FullName = objMsg.Sender
        .Email1Address = objMsg.SenderEmailAddress
        .Save
        End With

        End If
        '=================

        With objTask
        .Display
        .Categories = objMsg.Categories
        .Subject = objMsg.Subject & " (from: " & objMsg.Sender & ")"
        .Attachments.Add objMsg
        .Links.Add objContact
        End With

  75. kris says

    September 5, 2014 at 2:05 pm

    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.

    Reply
    • Diane Poremsky says

      September 8, 2014 at 10:42 pm

      This is probably the problem: Item As Outlook.MailItem - I'm guessing the notification is not seen as a mail item, it's program a report. Try item as object instead.

      Sub ConvertMailtoTask(Item As object)

      Reply
  76. Kyle says

    September 2, 2014 at 12:20 pm

    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.

    Reply
    • Diane Poremsky says

      September 2, 2014 at 5:45 pm

      You need to use the code in the section for "Save to a different tasks folder" and use the location of the second tasks folder in the code then copy it. It's also possible to set the folder and Add the task to it - either method works well but I don't have a sample on this page that uses Add.

      if you want to use a rule and only turn mail from account 2 into tasks, you can choose the sending account in the rule.

      Reply
      • Kyle says

        September 3, 2014 at 9:56 am

        Thank you for responding.

        I tried changing the account sending the rule, and it still defaulted to email1.

        I will research further on how to find how to set and add the outlook object to it in outlook vba somewhere. Thank you for pointing me in the right direction. If I am successful, I will post my findings.

  77. Russ B. says

    August 5, 2014 at 7:24 pm

    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!

    Reply
    • Diane Poremsky says

      August 5, 2014 at 8:27 pm

      After the task is created add this line:
      objMail.Move (Session.GetDefaultFolder(olFolderInbox).Folders("Converted to Tasks"))

      change the folder name and change objMail to item if you're using the first macro with 'item as mailitem' in it.

      Reply
  78. William Larson says

    July 30, 2014 at 5:17 pm

    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

    Reply
    • Diane Poremsky says

      July 31, 2014 at 1:21 am

      This should be item, not objmail: Subject = "Task 1" & objMail.Subject. Otherwise, it is working fine here - one task has a reminder in the morning, one in the evening.

      Reply
      • William Larson says

        July 31, 2014 at 1:46 am

        Thank you for your very kind assistance,
        I will make the change you suggested. You may want to do the same to the response you posted to Dave September 26, 2013 at 9:11 am. That is where I found the code to add the additional task. Thanks again for your help, Keep up the fine work.

      • Diane Poremsky says

        July 31, 2014 at 8:20 am

        Thanks, I will fix that code too. I looked at your code quite a few times before I noticed it.

  79. Bennett says

    June 30, 2014 at 9:04 am

    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,

    Reply
    • Diane Poremsky says

      July 3, 2014 at 8:51 am

      Interesting on using With in the file names - I'm not sure why it wouldn't work, while with is used in VBA, you'd have it wrapped in quotes.

      Reply
  80. Bennett says

    June 27, 2014 at 5:10 pm

    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?

    Reply
    • Diane Poremsky says

      June 27, 2014 at 9:42 pm

      Yes, you need to replace the code that creates the new task with code that uses the template.

      Set objTask = Application.CreateItemFromTemplate("template.oft")
      If it's a published form, try the published form name "ipm.task.mine", if that doesn't work , use item.add:
      Set objtask = Items.Add("ipm.note.name")

      Reply
      • Bennett says

        July 3, 2014 at 8:35 am

        The replacement code doesn't seem to be working. The custom task form is an ipm.task file but either doesn't work or gives me an error when I try the new code. Any tips?

      • Diane Poremsky says

        July 3, 2014 at 9:06 am

        Oops. You need to tell it which folder to use.
        Dim oFolder As Outlook.Folder
        Set oFolder = Application.Session.GetDefaultFolder(olFolderTasks)
        Set objTask = oFolder.Items.Add("IPM.Task.task with p2")

      • Bennett says

        July 3, 2014 at 9:15 am

        That's it! Thanks so much.

      • Bennett says

        July 8, 2014 at 12:33 pm

        I have a follow up question, what would the code look like to set the due date to "None"? Thanks,

      • Diane Poremsky says

        July 8, 2014 at 11:43 pm

        Enter the date as #1/1/4501# to get a value of none.

  81. Curt Faulk says

    June 26, 2014 at 7:35 pm

    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

    Reply
    • Diane Poremsky says

      July 3, 2014 at 8:48 am

      You need to use the correct variable for your objects:
      If objMail.Attachments.Count > 0 Then
      CopyAttachments objMail, objTask
      End If

      Reply
  82. Kevin Stanlay says

    June 18, 2014 at 3:42 pm

    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.

    Reply
    • Diane Poremsky says

      June 18, 2014 at 11:03 pm

      It is possible. See https://www.slipstick.com/developer/code-samples/create-meetings-csv-file/ for the method needs to get values from an excel sheet.

      Reply
  83. Mike Mc says

    June 18, 2014 at 1:14 pm

    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.

    Reply
  84. Haik says

    April 5, 2014 at 1:09 pm

    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?

    Reply
    • Diane Poremsky says

      April 6, 2014 at 11:45 pm

      Yes, you can do this. You need to refer to the field as .UserProperties("customfield")

      Reply
  85. Haik says

    April 5, 2014 at 4:05 am

    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

    Reply
  86. Haik says

    April 4, 2014 at 5:16 pm

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

    Reply
    • Diane Poremsky says

      April 5, 2014 at 1:19 am

      Yes, you'll use appointmentitem instead of taskitem and will use different fields.

      Reply
  87. Curt Faulk says

    March 25, 2014 at 11:38 am

    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!)

    Reply
  88. Curt Faulk says

    March 24, 2014 at 6:08 pm

    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!

    Reply
    • Diane Poremsky says

      March 25, 2014 at 12:40 am

      Well, considering i have 40 comments in the queue waiting for replies... I'm not that good. :)

      You'd change .Body = Item.Body

      to something like .body = item.subject & vbcrlf & item.sender & vbcrlf & item.to & vbcrlf & " -------------- " & vbcrlf & item.body

      You may need to use two vbcrlf together and may want to assign the fields to strings then put the strings together.

      Reply
  89. Mathieu Cote says

    March 20, 2014 at 10:23 am

    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))

    Reply
    • Diane Poremsky says

      March 20, 2014 at 2:27 pm

      Anything colored yellow or red? Syntax error often means a typo of some sort in the code.

      Reply
  90. cir0net says

    March 8, 2014 at 6:31 am

    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

    Reply
    • Diane Poremsky says

      March 19, 2014 at 12:23 am

      It should still work - do you get any error messages?

      Or... Rather than using createitem and Move, how about using item.add and save it to the folder directly?
      Set objTask = spsfolder.Items.Add(olTaskItem)

      Reply
  91. Nick Harger (@nickharger) says

    March 4, 2014 at 10:14 am

    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

    Reply
  92. Nick Harger (@nickharger) says

    March 4, 2014 at 9:21 am

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

    Reply
    • Diane Poremsky says

      March 4, 2014 at 9:54 am

      What is the complete macro you are trying to use? I'll try to repro the error.

      Reply
  93. Nick says

    February 26, 2014 at 1:39 pm

    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.

    Reply
    • Diane Poremsky says

      February 27, 2014 at 9:26 pm

      Is macro security set to low? Try adding MsgBox "it works!" as the first line of the macro - this will tell us if the macro is running.

      Reply
  94. Chris says

    January 24, 2014 at 5:48 am

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

    Reply
    • Diane Poremsky says

      January 25, 2014 at 1:29 am

      I thought I replied earlier. :( published forms are called using Add - Items.Add("ipm.tasks.another-task-final")

      Reply
  95. Chris says

    January 23, 2014 at 5:17 pm

    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!!!

    Reply
    • Diane Poremsky says

      January 23, 2014 at 8:26 pm

      This line: Set objTask = Application.CreateItem(olTaskItem)
      Needs to be changed to
      Set objTask = Application.CreateItemFromTemplate("C:\path\to\test.oft")

      Reply
  96. Can Kefeli says

    January 17, 2014 at 2:11 am

    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

    Reply
    • Diane Poremsky says

      January 17, 2014 at 8:24 am

      You also need to set it. Try .ReminderSet = True

      Reply
  97. Can Kefeli says

    January 17, 2014 at 1:24 am

    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 "https://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

    Reply
    • Diane Poremsky says

      January 17, 2014 at 1:49 am

      use debug.print after you set the variables - show the Immediate windows (Ctrl+G or the view menu) and see if the values are correct. The only thing I can think is that the date serial format is not putting the numbers in the correct order - it worked here with the US date format (mm/dd/yyyy).

      tarih = DateSerial(Mid(mesajicerik, tarihyeri + 10, 4), Mid(mesajicerik, tarihyeri + 15, 2), Mid(mesajicerik, tarihyeri + 18, 2))
      debug.print tarih
      debug.print Mid(mesajicerik, tarihyeri + 10, 4)
      debug.print Mid(mesajicerik, tarihyeri + 15, 2)
      debug.print Mid(mesajicerik, tarihyeri + 18, 2)

      Reply
  98. Can Kefeli says

    January 16, 2014 at 9:41 am

    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

    Reply
    • Diane Poremsky says

      January 16, 2014 at 9:59 am

      Can you post a sample of the message text you're searching? Is the date the last line of the message?

      Reply
  99. Can Kefeli says

    January 16, 2014 at 7:31 am

    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 "https://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

    Reply
    • Diane Poremsky says

      January 16, 2014 at 5:39 pm

      Using your text sample as entered here -

      No space:
      Hedef T:
      2014-01-31 09:48

      Space:
      tarihyeri = InStr(1, mesajicerik, "Hedef T: ")

      When remove the space, the due date is the date at Hedef T:.

      If that isn't the problem, we know the dateserial line is good.

      Reply
  100. Allen Hopson says

    November 16, 2013 at 11:43 am

    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!

    Reply
    • Diane Poremsky says

      November 17, 2013 at 6:37 am

      That setting is the problem. you can change it to the lowest level or use Seifert to sign it. Instructions are at https://www.slipstick.com/developer/how-to-use-outlooks-vba-editor/

      Reply
  101. Kevin says

    October 9, 2013 at 7:09 am

    Hi Diane,

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

    Thanks

    Reply
    • Diane Poremsky says

      October 9, 2013 at 8:25 am

      Add these two lines in the with statement - you can use an address or alias as long as outlook can resolve it, it will work.
      .Assign
      .Recipients.Add "email@address.com"

      Reply
  102. Dave says

    September 26, 2013 at 9:11 am

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

    Reply
    • Diane Poremsky says

      September 26, 2013 at 9:37 am

      That can be as simple as adding a second code block to the macro:

      Set objTask = Application.CreateItem(olTaskItem)
      With objTask
      .Subject = "Task 1" & item.Subject
      .StartDate = item.ReceivedTime
      .Body = item.Body
      .Categories = "Task1"
      .Save
      End With
      Set objTask = Nothing

      Reply
  103. Chris says

    September 16, 2013 at 12:58 pm

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

    Reply
  104. Chris says

    September 16, 2013 at 8:02 am

    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

    Reply
    • Diane Poremsky says

      September 16, 2013 at 9:22 am

      Check the Macro security. This usually means security was set back to not allow.

      Reply
  105. David Deblauwe says

    August 19, 2013 at 12:11 pm

    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

    Reply
    • Diane Poremsky says

      August 19, 2013 at 7:39 pm

      Use .Subject = Item.Subject & " " & Item.SenderEmailAddress to add the sender's address.

      Reply
  106. Jaime says

    July 12, 2013 at 10:59 am

    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.

    Reply
    • Diane Poremsky says

      July 12, 2013 at 11:17 am

      You would need to filter for RE, FW:

      If Left(LCase(Item.Subject), 3) = "fw:" or Left(LCase(Item.Subject), 3) = "re:" Then
      Exit Sub
      Else
      ' do whatever

      end if

      Reply
  107. Jaime says

    July 12, 2013 at 10:50 am

    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.

    Reply
    • Diane Poremsky says

      July 12, 2013 at 12:01 pm

      You'll need to calculate the due date and check it against the weekend - this assumes Mon- Fri workweek - stick it in before with objtask and change the .startdate to .startdate = dayDue

      Dim dayDue
      dayDue = Item.ReceivedTime + 2
      If Weekday(dayDue) = vbSaturday Then
      dayDue = dayDue + 2
      Else
      If Weekday(dayDue) = vbSunday Then
      dayDue = dayDue + 1
      End If
      End If

      Reply
  108. Ersula Washington says

    May 13, 2013 at 10:57 am

    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

    Reply
    • Diane Poremsky says

      May 13, 2013 at 5:03 pm

      If it was moved to Tasks, it should be a copy of the message - the code adds the message body to the task body. I've added a tutorial to this page that shows how its done.

      Reply
  109. moltra1 says

    May 2, 2013 at 1:44 pm

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

    Reply
    • Diane Poremsky says

      May 2, 2013 at 2:45 pm

      Tasks don't support HTMLBody, but you can try .Body = Item.HTMLBody. It should look as good (or bad) as dragging a message to the task folder to create a task.

      Reply
  110. Brian says

    April 30, 2013 at 1:54 pm

    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?

    Reply
    • Diane Poremsky says

      April 30, 2013 at 5:28 pm

      You mean this one? Create a task when a message is flagged You put this in ThisOutlookSession with the other code.

      Reply
  111. Brian says

    April 30, 2013 at 8:02 am

    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

    Reply
    • Diane Poremsky says

      April 30, 2013 at 8:33 am

      If you are using the VBA, Remove the .Body = Item.Body line and add
      Dim newAttachment As Outlook.Attachment
      Set newAttachment = objTask.Attachments.Add(Item, Outlook.OlAttachmentType.olEmbeddeditem)

      Reply
  112. Jack says

    April 9, 2013 at 9:43 pm

    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

    Reply
    • Diane Poremsky says

      April 9, 2013 at 10:29 pm

      What type of email account do you use? Are you right clicking on a message or going to Rules and Alerts? If you right click, you need to click Advanced. Run a Script is near the bottom of the Actions list of the Rules Wizard.

      Reply
  113. Tyler says

    April 4, 2013 at 10:52 pm

    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

    Reply
    • Diane Poremsky says

      April 5, 2013 at 2:17 pm

      You need to change this line -
      Set objTask = Application.CreateItem(olTaskItem)
      Set objTask = GetFolderPath("New PSTTest Cal")

      and use the function at use non-default folders

      Reply
  114. Terry T says

    March 26, 2013 at 1:35 pm

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

    Reply
    • Diane Poremsky says

      March 26, 2013 at 1:51 pm

      It should not be deleting the mail from the folder. At most, it will mark it read. Are you using a view that hides read messages?

      Are you using the rule method? If so, how does the Rule read?

      Reply
  115. sarah m says

    March 26, 2013 at 7:58 am

    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!

    Reply
    • mikulthegreat says

      May 27, 2015 at 6:56 pm

      How do you do that?

      Reply
      • Diane Poremsky says

        May 27, 2015 at 11:23 pm

        After End with line, add
        item.unread = false
        item.save

  116. Sharon says

    March 19, 2013 at 9:25 am

    Thanks very much! This is great.

    Reply
  117. Sharon says

    March 19, 2013 at 6:41 am

    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

    Reply
    • Diane Poremsky says

      March 19, 2013 at 8:00 am

      Yes, it would be possible to scan the mailbox on start up instead of using a rule to trigger a macro.

      Reply
    • Diane Poremsky says

      March 19, 2013 at 8:44 am

      Here is a version that checks new mail as it arrives in Outlook. It's really no different than using rules, but can handle processing a larger number of new messages better. It would also be possible to call a macro from Application_Startup, but that would only process existing email, not new mail as it arrives. Another option is using reminders to trigger a macro that checks the Inbox. This should run before rules, so any rule that adds categories or moves the message shouldn't affect it.

      This version looks for the word "Task:" at the beginning of a message, then creates a Task due tomorrow.

      Private Sub Application_Startup()
      Dim Ns As Outlook.NameSpace

      Set Ns = Application.GetNamespace("MAPI")
      Set oItems = Ns.GetDefaultFolder(olFolderInbox).Items

      End Sub

      Private Sub oItems_ItemAdd(ByVal Item As Object)
      If Left(Item.Subject, 5) = "Task:" Then
      Dim objTask As Outlook.TaskItem
      Set objTask = Application.CreateItem(olTaskItem)
      With objTask
      .Subject = Right(Item.Subject, Len(Item.Subject) - 6)
      .StartDate = Item.ReceivedTime + 1
      .Body = Item.Body
      .Save
      End With
      Item.Categories = "Made Task"
      Item.Save
      End If
      Set objTask = Nothing
      End Sub

      Reply
  118. Craig says

    March 15, 2013 at 5:35 pm

    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.

    Reply
    • Diane Poremsky says

      March 15, 2013 at 7:29 pm

      Yes, but you need to parse the text to locate the date. This is one method: https://www.slipstick.com/outlook-developer/parsing-text-fields-in-outlook/

      Reply
  119. Venetia says

    February 18, 2013 at 1:43 pm

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

    Reply
    • Diane Poremsky says

      February 18, 2013 at 9:53 pm

      What exactly do you need to do? It's hard to impossible to run rules on shared folders.

      Reply
  120. Carlos says

    February 6, 2013 at 11:09 am

    Me sirvió mucho, gracias

    Reply
  121. Michael says

    February 3, 2013 at 6:38 am

    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 (https://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)

    Reply
    • Diane Poremsky says

      February 3, 2013 at 9:33 am

      Changing flags to task every few minutes won't work, outlook doesn't have a timer feature. You can trigger macros from reminders though - so it is possible if you need some automation. If you use a lot of reminders you can trigger it with any reminder, otherwise, you'll need to use a recurring task or appointment. (If you send a lot of mail, item send event could trigger the macro). In the case of the macro at the other site, where you need to affect synced items, triggering a macro by an event probably the best option.

      If you want to create the task as you flag an item, use an item change event that creates the task when the item is flagged. See the quick flag example here.

      Reply
  122. John says

    January 29, 2013 at 9:23 am

    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

    Reply
    • Diane Poremsky says

      January 29, 2013 at 5:29 pm

      That error means you forgot to get the Copy Attachment function from this page

      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

      Reply
  123. John says

    January 25, 2013 at 6:56 am

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

    Reply
    • Diane Poremsky says

      January 25, 2013 at 8:41 am

      Yes. You only need 1 statement and it will loop to get all attachments.

      Reply
  124. Diane Poremsky says

    January 24, 2013 at 11:52 am

    BTW, if you just wanted ot add the email message as an attachment, you'd use
    Dim newAttachment As Outlook.Attachment

    Set newAttachment = objTask.Attachments.Add(Item, Outlook.OlAttachmentType.olEmbeddeditem)

    Reply
    • Mark says

      July 17, 2015 at 10:10 pm

      I'm using the code above under the heading "Create Task from the selected message" and trying to insert the code to add the email message as an attachment right after the objTask.save. But when I run the macro, it's neither creating the task nor attaching the message. Am I inserting the code in the right place?

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

      Next
      Set objTask = Nothing
      Set objMail = Nothing
      End Sub

      Reply
  125. John says

    January 24, 2013 at 11:32 am

    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!

    Reply
    • Diane Poremsky says

      January 24, 2013 at 11:50 am

      I have a script here somewhere that gets attachments... get the CopyAttachments function from the Copy appointments macro

      Stick this code before the objTask.save

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

      Reply
  126. Jon Spector says

    December 14, 2012 at 6:09 am

    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?

    Reply
    • Diane Poremsky says

      December 14, 2012 at 6:35 am

      No, the script is not stored on the server - it's in Outlook and Outlook needs to be running to use it. The rules that use Run a script action are 'this machine only' rules so they only run on the specific computer.

      Reply
  127. Ross Dickerson says

    November 19, 2012 at 7:41 am

    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?

    Reply
    • Diane Poremsky says

      November 19, 2012 at 3:57 pm

      If it worked in the test on the same machine, it's not the corp blocking it. Did you check the macro security settings? File, Options, Trust Center, Macro security in Outlook 2010 and 2013 or Tools, Macros, Security in older versions. Is the rule enabled?

      Reply
  128. Jeffrey Gage says

    November 17, 2012 at 9:06 am

    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?

    Reply
    • Diane Poremsky says

      November 17, 2012 at 1:26 pm

      You need to use getfolderpath

      Add the two bolded lines to the code and change the name of the tasks folder
      Set SPSFolder = GetFolderPath("SharePoint ListsYour Site - Tasks")
      Set objTask = Application.CreateItem(olTaskItem)
      -- snipped code --
      objTask.Save
      objTask.Move SPSFolder

      Reply
  129. Lee Edwards says

    November 16, 2012 at 12:52 pm

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

    Thanks

    Reply
  130. Lee Edwards says

    November 16, 2012 at 11:17 am

    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?

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

    Reply
    • Diane Poremsky says

      November 16, 2012 at 12:17 pm

      Possibly. I don't use Credenza so I don't know for sure. The big thing is whether Outlook can save or move to the credenza store. It would probably be best to ask Credenza support.

      Reply
  131. David says

    November 14, 2012 at 1:34 am

    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.

    Reply
    • Diane Poremsky says

      November 14, 2012 at 11:29 am

      You'd need to check search the existing tasks for a match, so it would require a bit of additional coding.

      Reply
  132. Jon says

    August 10, 2012 at 6:09 am

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

    Reply
  133. Jeff says

    June 29, 2012 at 2:15 pm

    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.

    Reply
    • Diane Poremsky says

      June 29, 2012 at 2:50 pm

      I forget offhand if you can use custom fields, but try this:

      objTask.customfield = left (Item.body,20) 'where 20 is the # of characters you want from the first line

      The results might be goofy if the first line is shorter than 20 (or whatever number you choose), so you'll probably want to get the line length and calculate it. I don't have any code samples for that committed to memory though.

      Reply
  134. Timo says

    June 27, 2012 at 12:46 am

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

    Reply
    • Diane Poremsky says

      June 27, 2012 at 5:24 am

      Tasks have flags by default. You might want due date & reminders -
      objTask.DueDate = objMail.ReceivedTime + 3 ' due in 3 days
      objTask.ReminderSet = True
      objTask.ReminderTime = objTask.DueDate - 0.25 ' this is 6 hours before its due

      A filtered view might help - or assigning a category. Create a category and assign a color then add objTask.Categories = "Category-name" above the line that saves it. Filter task list shows how to hide flagged email, but you can use the same method to hide or show tasks meeting other conditions.

      Reply
  135. Ike says

    May 4, 2012 at 9:45 am

    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.

    Reply
    • Diane Poremsky says

      May 4, 2012 at 10:51 am

      Adding the attachment to a task is possible, taking content from the attachment and using it to create a task would take a lot more code.

      Reply
  136. Jesse says

    April 6, 2012 at 10:58 am

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

    Reply
  137. Jason says

    January 20, 2012 at 12:58 am

    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.

    Reply
    • Diane Poremsky says

      January 20, 2012 at 2:45 am

      Of course it's possible. The code needs just a little tweaking -
      Sub ConvertMailtoTask()
      Dim objTask As Outlook.TaskItem
      Dim objMail As Outlook.MailItem

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

      objTask.Subject = objMail.Subject
      objTask.StartDate = objMail.ReceivedTime
      objTask.Body = objMail.Body
      objTask.Save

      Next
      Set objTask = Nothing
      Set objMail = Nothing
      End Sub

      Reply
  138. Mike Hearn says

    January 17, 2012 at 7:49 pm

    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

    Reply
    • Diane Poremsky says

      January 17, 2012 at 9:45 pm

      I'm not 100% sure what you are asking - if you mean in the view when you open the contacts folder, it's either the view settings (for address card and other views) or the business card settings.

      On the address card and other views, its as simple as changing the view. For business cards, you need to change every card. If you want this as default, see https://www.slipstick.com/outlook/contacts/change-.../ and https://www.slipstick.com/outlook/using-custom-bus...

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 31 Issue 7

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Reset the New Outlook Profile
  • Disable "Always ask before opening" Dialog
  • This operation has been cancelled due to restrictions
  • How to Hide or Delete Outlook's Default Folders
  • Change Outlook's Programmatic Access Options
  • Use Public Folders In new Outlook
  • Removing Suggested Accounts in New Outlook
  • How to Delete Stuck Read Receipts
  • Sync Issues and Errors with Gmail and Yahoo accounts
  • Error Opening iCloud Appointments in Classic Outlook
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Sync Issues and Errors with Gmail and Yahoo accounts

Error Opening iCloud Appointments in Classic Outlook

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2026 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.