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

Create Task or Appointment and Insert Selected Text

Slipstick Systems

› Developer › Code Samples › Create Task or Appointment and Insert Selected Text

Last reviewed on August 29, 2018     27 Comments

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).
create a task from the selection

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

Copy selected text to an appointment

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:

  1. Right click on Project1 and choose Insert > Module
  2. 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.

  1. Go to Tools, References menu.
  2. 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.)
    Reference the Word object model in Outlook's VBA Editor

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

More Information

  • Automatically create a task when sending a message
  • Create a Task from an Email using a Rule
  • Create an Outlook Appointment from a Message
  • Create Tasks from Email and move to different Task folders
  • Replicate GTD: Create a task after sending a message
Create Task or Appointment and Insert Selected Text was last modified: August 29th, 2018 by Diane Poremsky

Related Posts:

  • Create a Task and copy to another Tasks folder
  • Create an Outlook Appointment from a Message
  • Replicate GTD: Create a task after sending a message
  • Insert Emoji using VBA

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
27 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Rob
March 22, 2023 5:34 pm

@5
Wanted to follow up on my comment from last year. I've come back to this topic, trying to see if I can get it to work correctly. Still seeing same behavior: the selected text only gets added to the task when I have the VBA editor open. Otherwise only the email gets attached, while the selected text is not inserted.
Any thoughts on why this happens - and how I could solve it?
I'm using Outlook on M365.

Rob 

0
0
Reply
Rob
April 13, 2022 4:28 am

Hi Diane - thanks for this code, it's exactly what I was looking for: creating a task with both the email body text AND the email attached to the task.

Strange thing that I'm coming across is that the macro works well when I have the VBA editor open - both email body and attached email are there.
When I close the VBA editor though and run the macro, the task gets created only with the attached email. The email body text doesn't get copied into the task - when going back to the email I do see that the whole email body is still selected.

Any idea what causes this to happen? I'm on Outlook 365 BTW.
Thanks.

Rob

0
0
Reply
Caleb
February 27, 2020 3:33 am

Hi Diane and thank you VERY much for all the great work and examples on your site!

I too am trying to get the attachments in the email added as attachments to the task, but do not succeed. (whereas the rest is working, i.e. adding email text in body of task and email also as attachment) .

Per your posts I add the following to the bottom of your original command. I do NOT get any errors, but the attachments to the email fail to be created as task attachments...

Sub CopyAttachments(objSourceItem, objTargetItem)
'Cannot get this part to work (to copy attachments)
   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

Is there anything more one should do than add the above under your original command?

Thanks in advance!!

0
0
Reply
username
Reply to  Caleb
October 8, 2022 12:05 pm

Hi Caleb. Did you ever figure this out? I have the same question

0
0
Reply
A Colmenares
January 4, 2017 12:50 pm

Another question. Is there a way of adding to the task any attachments that came in the original message? That is actually the only reason i need to attach the original message: to be able to access the attachments that are in the original message. But if there is a way of copying the text and adding the attachments, that would make it.

0
0
Reply
Diane Poremsky
Author
Reply to  A Colmenares
January 4, 2017 11:44 pm

you can. You'd save the attachment from the message then add it to the task. A working sample of the method is at
https://www.slipstick.com/outlook/email/reply-replyall-attachments/

You'd use
CopyAttachments oItem, oTask
when you create the task and use the copyAttachments function:
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

Last edited 4 years ago by Diane Poremsky
0
0
Reply
A Colmenares
Reply to  Diane Poremsky
January 5, 2017 4:22 am

Thank you for your quick response. I'm glad to know it can actually be done. I'm not very good at VBA, so after trying for a couple of hours to figure it out on my own and not succeeding I figured it would be easier to ask. Could you send me how the whole macro goes? (The one to create the task with the text and the original message attached works fine, I would just need to add the part of adding also the attachments). I hope it is not too much to ask.

0
0
Reply
A Colmenares
Reply to  Diane Poremsky
January 5, 2017 7:04 am

Thank you for your response. I already added the copyAttachments function at the bottom. I didn't understand the part of adding the CopyAttachments oItem, oTask part. Where and what exactly would I have to copy into the macro?

0
0
Reply
A Colmenares
January 4, 2017 12:46 pm

Great Macro. It has saved me a lot of time. One question. Is there a way of having the original message attached at the beginning of the text and not at the end? I guess it's a matter of changing the order of the commands in VBA, but I haven't been able to figure it out yet.

0
0
Reply
Diane Poremsky
Author
Reply to  A Colmenares
January 4, 2017 11:40 pm

It might be possible using word object model to insert the attachment object at the top. I don't think i have any code samples that do that using an attachment though.

0
0
Reply
Doug
December 15, 2016 11:01 am

How about adding a calendar appointment to a shared calendar, and pasting the clipboard contents into the body? I've gotten close, but can't seem to make it work. Thanks!!!!!

0
0
Reply
Diane Poremsky
Author
Reply to  Doug
January 4, 2017 11:35 pm

I use the macro here to copy a message body to an appointment.
https://www.slipstick.com/developer/code-samples/create-outlook-appointment-from-message/

You'd set the folder and use items.add (or move to the shared calendar)
Set objOwner = NS.CreateRecipient("maryc")
objOwner.Resolve
If objOwner.Resolved Then
'MsgBox objOwner.Name
Set newCalFolder = NS.GetSharedDefaultFolder(objOwner, olFolderCalendar)
set olAppt = newCalFolder.Items.Add(olAppointmentItem)

Last edited 4 years ago by Diane Poremsky
0
0
Reply
A Colmenares
November 15, 2016 9:38 am

What would I need to add to the script if I want the original message deleted from the inbox after the task is created?

0
0
Reply
Diane Poremsky
Author
Reply to  A Colmenares
November 15, 2016 4:31 pm

add objMail.Delete after the task is created.

0
0
Reply
Peter Hawkes
July 1, 2016 1:28 am

Running Create Appointment and Insert Selection gives me an error - Compile Error: Cant find project or library on the line Set objWord = objDoc.Application

I have the Microsoft Word 16.0 Object Library selected in References?

0
0
Reply
Diane Poremsky
Author
Reply to  Peter Hawkes
July 1, 2016 8:40 am

That should be the cause of that error. If you didn't have the GetCurrentItem Function, i'd expect a different error. Try unchecking it, click ok then reselect it.

0
0
Reply

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

Latest EMO: Vol. 30 Issue 32

Subscribe to Exchange Messaging Outlook






Support Services

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

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
Ajax spinner

Recent Bugs List

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

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

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

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

Office Update History

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

Outlook Suggestions and Feedback

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

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

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

Other Microsoft 365 applications and services




New Outlook Articles

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

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

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

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

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

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

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

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

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

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment