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 SubYou 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.
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 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:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
More information as well as screenshots are at How to use the VBA Editor
More Information
Other macros to create tasks or appointments are at
Josh says
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!
Brian Stone says
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.
Brian Stone says
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.
Diane Poremsky says
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
Brian Stone says
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 SubApologies, still learning.
Kind Regards
Sherlin says
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)
Diane Poremsky says
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.
Cischology says
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?
Diane Poremsky says
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
cischology says
Thank you for your quick reply, however, it does not seem to change anything no matter which option I chose.
Diane Poremsky says
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
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
I'll have to think on the best way to do this - duplicate checking macros can be slow.
Edward says
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!
Diane Poremsky says
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")
CharlesC says
Hi Diane,
I Just want to sincerely thank you for all the valuable information you contribute. It has literally saved me days of work.
Neil says
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!
Diane Poremsky says
The last macro should add it as an attachment -
'Add the message as an attachment
.Attachments.Add objMail
Neil says
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
Neil says
changed ot this - seems ot work
SubCreateNewTask(ItemAsOutlook.MailItem)DimxNewTaskAsTaskItemOnErrorResumeNextSetxNewTask = Outlook.CreateItem(olTaskItem)WithxNewTask.Subject = Item.Subject.StartDate = Item.ReceivedTime.DueDate = Item.ReceivedTime + 1.Body = Item.Body.Importance = olImportanceHigh.SaveEndWithSetxNewTask =NothingEndSubRob says
in the .Subject = item.subject , what if I want to add additional text to the subject for example the word Follow up: Subject
Diane Poremsky says
Use
.Subject = "followup: " & item.subject
Kimberly Cope says
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.
Diane Poremsky says
Yes, the macro can move the message. Use
objMail move [folder]
RMK says
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?
Diane Poremsky says
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/
RMK says
Awesome! Would you share it (or did I miss it)?
Diane Poremsky says
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
MTR says
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
MTR says
Photo of code attached. I am using Outlook 365.
MTR says
For reference I am using Office 365.
Diane Poremsky says
Do you receive any error messages? It looks like it should work.
AUBREY says
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
Diane Poremsky says
What was the secret trick? It may help others facing the same problem.
AUBREY says
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
>> 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
I will try that and let you know. Thanks again. Your site has been very useful.
AUBREY says
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"
Diane Poremsky says
>> 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)
AUBREY says
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.
Ankit says
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.
Diane Poremsky says
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
Ankit says
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
Diane Poremsky says
Yes, you can pick up an address from a message.
Ankit says
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 ?
Diane Poremsky says
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.
Luis castanheiro says
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
Diane Poremsky says
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)
Luis castanheiro says
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
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
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
Remove that CopyAttachments macro - you have a second copy of it somewhere.
Ankit says
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
Diane Poremsky says
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.
Luis castanheiro says
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
Diane Poremsky says
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/
Ankit says
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 ?
Diane Poremsky says
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)
Diane Poremsky says
For your example in an earlier comment, the path would be something like
Set SPSFolder = GetFolderPath("SharePoint Lists\Stericycle_Program_Site - Action Item Tracker")
Ankit says
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
Diane Poremsky says
i will test it, but you definitely need to use .add - create item uses the default folder.
Ankit says
Please let me know if I need to do some changes in existing code.
Diane Poremsky says
The code works fine here. Is it still erroring for you?
Ankit says
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 !
Diane Poremsky says
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
Ankit says
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
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?
Ankit says
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
Diane Poremsky says
Any error messages?
Ankit says
Diane, no error message displayed. It's just the code is not working.
Thomas says
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?
Diane Poremsky says
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
Stephanie says
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?
Diane Poremsky says
Is this line in your code?
newAttachment.Add Item, olEmbeddeditem
delete it.
Alex Mak says
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.
Diane Poremsky says
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.
Alex says
If I need to dynamically accept a different start date as stated in the message body. How should the codes be changed?
Diane Poremsky says
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.
Alex says
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
Diane Poremsky says
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.
Jahel Vella says
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
John Carlos says
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.
Diane Poremsky says
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/
Mist says
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
Diane Poremsky says
What happens when you use it? If you lose the message body, put the if line ahead of the body line.
Mist says
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
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
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
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
I would also like to know if this code would work in outlook 2013 and 2010 as well.
Thanks
Diane Poremsky says
Yes, it will. It should work back to at least 2003.
Mist says
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.
Al Ameen says
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
Diane Poremsky says
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
Kelvin Hux says
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.
Diane Poremsky says
add item.unread = true before end sub to make sure they are unread. (You shouldn't need item.save to save the unread state.)
Kelvin Hux says
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
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
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
Wynand Becker says
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?
Diane Poremsky says
Yes, you just need to grab that address
At the most basic, it's simply
.Recipients.Add item.cc
or
.Recipients.Add item.to
Tim says
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?
Diane Poremsky says
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.
Tim says
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
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.
Taher says
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 ?
Diane Poremsky says
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")
Joe says
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
Diane Poremsky says
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
Joe says
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
Sure, change .Save to .display (or add .display right before or after .Save)
Alaa says
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
Diane Poremsky says
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.
Alaa says
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
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)
AAP says
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!
Diane Poremsky says
Sure, remove the .startdate and .duedate lines, if present in the code.
Haim Moshe says
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
Diane Poremsky says
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.
MUGAHID M FARAJ says
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.
Diane Poremsky says
i'll need to think on this one, it fairly complicated.
Martin Rene Rasmussen says
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.
Diane Poremsky says
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.
Esther Perron says
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 .
Diane Poremsky says
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.
Joshua says
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
Diane Poremsky says
There is a flag sent messages macro at https://www.slipstick.com/developer/code-samples/set-flag-follow-up-using-vba/ that does this.
Davd says
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
Diane Poremsky says
After End With line, add
objMail.Categories = "Added to Tasks" & objMail.Categories
if it doesn't seem to work, add another line: objmail.save
Andrew says
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?
Diane Poremsky says
Do you have macro security set to low? Did you restart Outlook?
LAM says
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?
Diane Poremsky says
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/
Soran says
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..
Diane Poremsky says
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.
Mac says
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 :)
Diane Poremsky says
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.
Curt Faulk says
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.)
Diane Poremsky says
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.
Diane Poremsky says
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
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
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
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
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
Perfect. As usual, you have been exceedingly helpful.
Ryan says
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?
Diane Poremsky says
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?
Bill Moore says
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..
Diane Poremsky says
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.
Alex says
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!
Diane Poremsky says
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.
Brent Jones says
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?
Diane Poremsky says
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/
Luis says
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
Diane Poremsky says
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.
Luis says
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
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
Jake says
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?
Diane Poremsky says
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)
Mike says
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
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/
Simon Spence says
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.
Diane Poremsky says
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.
Simon Spence says
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?
Webmaster says
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.
Thibaud says
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
Atasha says
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.
Diane Poremsky says
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.
mikulthegreat says
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?
Diane Poremsky says
At the beginning, you can check the read state:
if item.unread = true then
'create task
.unread= false
end if.
Sumeet says
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
Diane Poremsky says
No, sorry, it cannot run on the server.
Jatin says
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
Diane Poremsky says
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
Bennett says
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?
Diane Poremsky says
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.
Jack Coole says
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?
Diane Poremsky says
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.
Alita says
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?
Alexis Hernandez says
yes, that's exactly what I need. I tried researching how to format my own codes and cant seem to find how... any suggestions?
Diane Poremsky says
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.
Alexis Hernandez says
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
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
how would I configure that automatic email to be sent out using a macro & rules?
Diane Poremsky says
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
I threw those code samples together to create the sample in this file: send task update
Alexis Hernandez says
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
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.
Alexis Hernandez says
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.
Diane Poremsky says
So you want to create a task from an email then send the person who sent you the email a completed status report?
Alexis Hernandez says
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.
Diane Poremsky says
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
Matthew Schwarz says
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.
Diane Poremsky says
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.
Thiago says
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.
Diane Poremsky says
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.
Thiago says
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
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
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.
Russ B. says
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!
Diane Poremsky says
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.
David Nestlebush says
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
Diane Poremsky says
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().
John says
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
Diane Poremsky says
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.
John says
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
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
"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
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
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
kris says
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.
Diane Poremsky says
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)
Kyle says
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.
Diane Poremsky says
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.
Kyle says
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.
Russ B. says
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!
Diane Poremsky says
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.
William Larson says
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
Diane Poremsky says
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.
William Larson says
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
Thanks, I will fix that code too. I looked at your code quite a few times before I noticed it.
Bennett says
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,
Diane Poremsky says
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.
Bennett says
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?
Diane Poremsky says
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")
Bennett says
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
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
That's it! Thanks so much.
Bennett says
I have a follow up question, what would the code look like to set the due date to "None"? Thanks,
Diane Poremsky says
Enter the date as #1/1/4501# to get a value of none.
Curt Faulk says
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
Diane Poremsky says
You need to use the correct variable for your objects:
If objMail.Attachments.Count > 0 Then
CopyAttachments objMail, objTask
End If
Kevin Stanlay says
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.
Diane Poremsky says
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.
Mike Mc says
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.
Haik says
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?
Diane Poremsky says
Yes, you can do this. You need to refer to the field as .UserProperties("customfield")
Haik says
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
Haik says
Is it possible to create an appointment in the calender with this script, instead of a task?
Diane Poremsky says
Yes, you'll use appointmentitem instead of taskitem and will use different fields.
Curt Faulk says
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!)
Curt Faulk says
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!
Diane Poremsky says
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.
Mathieu Cote says
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))
Diane Poremsky says
Anything colored yellow or red? Syntax error often means a typo of some sort in the code.
cir0net says
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
Diane Poremsky says
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)
Nick Harger (@nickharger) says
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
Nick Harger (@nickharger) says
It still has the same error. It worked for a few moments before the "loading window" goes back to disappearing.
Diane Poremsky says
What is the complete macro you are trying to use? I'll try to repro the error.
Nick says
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.
Diane Poremsky says
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.
Chris says
Thank you, and if I've saved the custom form in the personal forms library, what should I do?
Diane Poremsky says
I thought I replied earlier. :( published forms are called using Add - Items.Add("ipm.tasks.another-task-final")
Chris says
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!!!
Diane Poremsky says
This line: Set objTask = Application.CreateItem(olTaskItem)
Needs to be changed to
Set objTask = Application.CreateItemFromTemplate("C:\path\to\test.oft")
Can Kefeli says
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
Diane Poremsky says
You also need to set it. Try .ReminderSet = True
Can Kefeli says
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
Diane Poremsky says
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)
Can Kefeli says
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
Diane Poremsky says
Can you post a sample of the message text you're searching? Is the date the last line of the message?
Can Kefeli says
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
Diane Poremsky says
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.
Allen Hopson says
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!
Diane Poremsky says
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/
Kevin says
Hi Diane,
I would like to auto assign this task to another team member, how would i do this?
Thanks
Diane Poremsky says
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"
Dave says
I would like to create 2 tasks for certain emails how would I go about doing this?
Diane Poremsky says
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
Chris says
Thank you. That was the problem. Works fine again now.
Chris says
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
Diane Poremsky says
Check the Macro security. This usually means security was set back to not allow.
David Deblauwe says
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
Diane Poremsky says
Use .Subject = Item.Subject & " " & Item.SenderEmailAddress to add the sender's address.
Jaime says
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.
Diane Poremsky says
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
Jaime says
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.
Diane Poremsky says
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
Ersula Washington says
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
Diane Poremsky says
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.
moltra1 says
Is there a way to copy the format of the email text to the task. i.e. if the email had tables in it.
Diane Poremsky says
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.
Brian says
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?
Diane Poremsky says
You mean this one? Create a task when a message is flagged You put this in ThisOutlookSession with the other code.
Brian says
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
Diane Poremsky says
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)
Jack says
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
Diane Poremsky says
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.
Tyler says
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
Diane Poremsky says
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
Terry T says
Diane I love this macro. I just wish it would not delete the e-mail from the folder. Can you help me out?
Diane Poremsky says
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?
sarah m says
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!
mikulthegreat says
How do you do that?
Diane Poremsky says
After End with line, add
item.unread = false
item.save
Sharon says
Thanks very much! This is great.
Sharon says
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
Diane Poremsky says
Yes, it would be possible to scan the mailbox on start up instead of using a rule to trigger a macro.
Diane Poremsky says
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
Craig says
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.
Diane Poremsky says
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/
Venetia says
Bump!
:)
Hi Diana - any chance you have advice on how to setup an auto-rule to a sahred task folder?
Diane Poremsky says
What exactly do you need to do? It's hard to impossible to run rules on shared folders.
Carlos says
Me sirvió mucho, gracias
Michael says
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)
Diane Poremsky says
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.
John says
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
Diane Poremsky says
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
John says
So just one "if Item.Attachment.Count..." statement, right?
Diane Poremsky says
Yes. You only need 1 statement and it will loop to get all attachments.
Diane Poremsky says
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)
Mark says
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
John says
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!
Diane Poremsky says
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
Jon Spector says
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?
Diane Poremsky says
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.
Ross Dickerson says
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?
Diane Poremsky says
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?
Jeffrey Gage says
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?
Diane Poremsky says
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
Lee Edwards says
OK and i asked and they said they would make it a product suggestion
Thanks
Lee Edwards says
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#
Diane Poremsky says
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.
David says
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.
Diane Poremsky says
You'd need to check search the existing tasks for a match, so it would require a bit of additional coding.
Jon says
Thanks for the very useful code - You are truly Most Valuable!
Jeff says
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.
Diane Poremsky says
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.
Timo says
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...
Diane Poremsky says
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.
Ike says
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.
Diane Poremsky says
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.
Jesse says
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...
Jason says
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.
Diane Poremsky says
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
Mike Hearn says
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
Diane Poremsky says
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...