My article at "Create a Task from an Email using a Rule" shows how to create a task from an email message but what if only want to include the actionable part of the message in the task?
You don't actually need a macro to do this - Outlook has a pretty cool feature built in that makes this easy: just select the text and drag to the Tasks button on the navigation pane and drop. A new task form opens with the selected text in the task body, ready for you to fill out the subject and dates.
You can drag text to any folder to create an item with the text in the body field; this method can be used to create an appointment, contact, new message, or a note.It's not limited to content already in Outlook - you can drag a selection in a web page in Edge in Windows 10 (this worked in IE in old versions of Windows & Outlook) or Word.
If an application doesn't support dragging, you can copy and paste in a folder to create a new item. You'll need to use Ctrl+V to paste after clicking on the list pane - the folder should be highlighted gray (inactive selection), not blue.
While you don't need a macro to do this, using a macro can save time. It can automatically add a subject (any predefined subject of your choosing, such as using the sender's name, received date, or message subject) and it can set start and due dates.
Dropping text on the Task button creates the task in the default Tasks folder; a macro can add it to a different tasks folder. If you're not good at dragging (not ususual if you're using a touch pad), a macro is one click.
If you routinely create tasks using content copied from other applications, a macro can create the task using the content on the clipboard.
Create Task Using Selected Text
To use this macro: Select the text you want in the Task then run the macro (add it to the ribbon for easy access). If you want to copy the entire message body, the macro can select it for you, by adding .WholeStory before the .Copy line.
This macro creates a task with a date date 3 days from the email's received date and adds the original message as an attachment. The formatting of the selected message carries into the task (including images).
Before using this macro you need to do two things: get the GetCurrentItem function from "Outlook VBA: Work with Open Item or Selected Item" (this allows you to use the macro with open or selected messages) and select the Microsoft Word Object Library in the VB Editor's Tools, References. You also need to have macro security set to low.
By using the Word Object Library, we can use Word's VBA commands to copy a selection in the message body and paste it into the Task or Appointment, all of which use Word as the editor.
Sub ConvertSelectionToTask() ' You need the GetCurrentItem Function from 'http://slipstick.me/e8mio Dim objTask As Outlook.TaskItem Dim objMail As Outlook.MailItem ' Add reference to Word library ' in VBA Editor, Tools, References Dim objWord As Word.Application Dim objInsp As Inspector Dim objDoc As Word.Document Dim objSel As Word.Selection On Error Resume Next Set objMail = GetCurrentItem() Set objTask = Application.CreateItem(olTaskItem) If Not objMail Is Nothing Then If objMail.Class = olMail Then Set objInsp = objMail.GetInspector If objInsp.EditorType = olEditorWord Then Set objDoc = objInsp.WordEditor Set objWord = objDoc.Application Set objSel = objWord.Selection With objSel 'use wholestory to copy the entire message body ' .WholeStory .Copy End With End If End If End If Set objInsp = objTask.GetInspector Set objDoc = objInsp.WordEditor Set objSel = objDoc.Windows(1).Selection With objTask .Subject = objMail.Subject .DueDate = objMail.ReceivedTime + 3 .StartDate = objMail.ReceivedTime + 2 objSel.PasteAndFormat (wdFormatOriginalFormatting) .Categories = "From Email" ' .Save .Save .Display .Attachments.Add objMail End With objMail.Categories = "Task" & objMail.Categories Set objTask = Nothing Set objMail = Nothing Set objSel = Nothing Set objInsp = Nothing Set objWord = Nothing End Sub
Create Appointment and Insert Selection
This version of the macro creates an appointment and inserts the selected text (including formatting) into the appointment body. If you want to copy the entire message body, the macro can select it for you, using .WholeStory before the .Copy line.
Instead of inserting a copy of the original message as an attachment as the Task macro does, it inserts a link to the original message (the link may not work if the message is moved).
This macro uses the next appointment period for the start date and time (Outlook's default).
Sub ConvertSelectionToAppointment() ' You need the GetCurrentItem Function from 'http://slipstick.me/e8mio Dim objAppt As Outlook.AppointmentItem Dim objMail As Outlook.MailItem Dim strID As String Dim strLink, strLinkText As String ' Add reference to Word library ' in VBA Editor, Tools, References Dim objInsp As Inspector Dim objDoc As Word.Document Dim objSel As Word.Selection Set objMail = GetCurrentItem() strID = objMail.EntryID strLink = "outlook:" & strID strLinkText = objMail.Subject On Error Resume Next If Not objMail Is Nothing Then If objMail.Class = olMail Then Set objInsp = objMail.GetInspector If objInsp.EditorType = olEditorWord Then Set objDoc = objInsp.WordEditor Set objWord = objDoc.Application Set objSel = objWord.Selection With objSel 'use wholestory to copy the entire message body ' .WholeStory .Copy End With End If End If End If Set objAppt = Application.CreateItem(olAppointmentItem) Set objInsp = objAppt.GetInspector Set objDoc = objInsp.WordEditor Set objSel = objDoc.Windows(1).Selection With objAppt .Subject = objMail.Subject .Categories = "From Email" '.Attachments.Add objMail objSel.PasteAndFormat (wdFormatOriginalFormatting) objSel.Range.InsertParagraphBefore objSel.Range.InsertParagraphBefore objDoc.Hyperlinks.Add objSel.Range, strLink, "", "", strLinkText, "" objSel.Range.InsertBefore vbCrLf & " Link to message: " & vbCrLf '.Save .Display End With objMail.Categories = "Appt" & objMail.Categories Set objAppt = Nothing Set objMail = Nothing End Sub
Clipboard to Tasks
This macro creates a task with the contents of the clipboard added to the task body. As with the other macros, you need to set a reference to Word's Object library in Tools, References.
Private Sub ClipboardToTask() Dim objTask As Outlook.TaskItem ' Add reference to Word library ' in VBA Editor, Tools, References Dim objWord As Word.Application Dim objInsp As Inspector Dim objDoc As Word.Document Dim objSel As Word.Selection On Error Resume Next Set objTask = Application.CreateItem(olTaskItem) Set objInsp = objTask.GetInspector Set objDoc = objInsp.WordEditor Set objSel = objDoc.Windows(1).Selection With objTask .DueDate = Now + 3 .StartDate = Now + 2 .ReminderSet = True .ReminderTime = .DueDate + "2:00:00 PM" objSel.PasteAndFormat (wdFormatOriginalFormatting) .Display End With Set objTask = Nothing Set objSel = Nothing Set objInsp = Nothing Set objWord = Nothing End Sub
How to use the macros on this page
First: You need to have macro security set to the lowest setting, Enable all macros during testing. The macros will not work with the top two options that disable all macros or unsigned macros. You could choose the option Notification for all macros, then accept it each time you restart Outlook, however, because it's somewhat hard to sneak macros into Outlook (unlike in Word and Excel), allowing all macros is safe, especially during the testing phase. You can sign the macro when it is finished and change the macro security to notify.
To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, look 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.
Macros that run when Outlook starts or automatically need to be in ThisOutlookSession, all other macros should be put in a module, but most will also work if placed in ThisOutlookSession. (It's generally recommended to keep only the automatic macros in ThisOutlookSession and use modules for all other macros.) The instructions are below.
The macros on this page should be placed in a module.
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.
Set a reference to other Object Libraries
If you receive a "User-defined type not defined" error, you need to set a reference to another object library.
- Go to Tools, References menu.
- Locate the object library in the list and add a check mark to it. (Word and Excel object libraries version numbers will match Outlook's version number.)
Commonly used libraries are Microsoft Word, Microsoft Excel, Microsoft Forms, and VBScript Regular Expression.
More information as well as screenshots are at How to use the VBA Editor