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

Automatically create a task when sending a message

Slipstick Systems

› Developer › Code Samples › Automatically create a task when sending a message

Last reviewed on February 13, 2019     53 Comments

This application startup macro watches for the user to send an email and asks if they want to create a task for the message. If they choose no, the message is sent. If they select yes then a task is created before the message is sent.

Create a task for the sent message

The code adds the message recipients to the task body, along with the message body. The start date is "today" (when the message is sent) and the due date is 2 days from now. The reminder is set for 2 days from now at 9 AM.

Create task from email

To automatically create tasks for messages you receive, see Create a Task from an Email using a Rule

Create task from sent message macro

To use this macro:

  1. Set macro security to low.
  2. Open the VBA Editor (Alt+F11)
  3. Expand Project1 to find ThisOutlookSession
  4. Copy the macro and paste at the top of ThisOutlookSession

Edit the start date, due date, and reminder time fields as needed.

To test the macro, click in the Application_Startup procedure and click the Run button then send a message.

May 14 2018: update the code to fix a problem where the reminder was set for the beginning of this month, if creating the task at the end of the month.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    
Dim intRes As Integer
Dim strMsg As String
Dim objTask As TaskItem
Set objTask = Application.CreateItem(olTaskItem)
Dim strRecip As String

 strMsg = "Do you want to create a task for this message?"
 intRes = MsgBox(strMsg, vbYesNo + vbExclamation, "Create Task")
      
    If intRes = vbNo Then
      Cancel = False
    Else
      
    For Each Recipient In Item.Recipients
        strRecip = strRecip & vbCrLf & Recipient.Address
    Next Recipient

With objTask
    .Body = strRecip & vbCrLf & Item.Body
    .Subject = Item.Subject
    .StartDate = Item.ReceivedTime
' Can use Now + nn for the start and/or due dates
 '   .DueDate = Now + 10
 '   .StartDate = Now + 9

    .ReminderSet = True
    .ReminderTime = Now + 2 + #9:00:00 AM#
' alternately, use the due date to set the reminder:
'   .ReminderTime = .DueDate - 2 + #2:00:00 PM#

    .Save
End With

    Cancel = False
      
    End If

Set objTask = Nothing
    
End Sub

 

Add Sent Message as attachment

If you want to add the sent message as an attachment, you can't use .Attachments.add because it adds a blank message. One way to do it is to watch the Sent folder for a new item and attach it to the Task.

While you could use the Itemsend macro then add the attachment after the message is moved to the sent folder, this version of the macro watches the sent folder and asks if you want to create at task after the message is sent.

You'll need to restart Outlook or click in the Application_Startup macro then click Run to start the macro.

Private objNS As Outlook.NameSpace
Private WithEvents objItems As Outlook.Items

Private Sub Application_Startup()
 
Dim objWatchFolder As Outlook.Folder
Set objNS = Application.GetNamespace("MAPI")

'Set the folder and items to watch:
Set objWatchFolder = objNS.GetDefaultFolder(olFolderSentMail)
Set objItems = objWatchFolder.Items

Set objWatchFolder = Nothing
End Sub

Private Sub objItems_ItemAdd(ByVal Item As Object)
Dim sentMsg As Object
Dim objTask As TaskItem
Dim intRes As Integer
Dim strMsg As String
Set objTask = Application.CreateItem(olTaskItem)
Dim strRecip As String

 strMsg = "Do you want to create a task for this message?"
 intRes = MsgBox(strMsg, vbYesNo + vbExclamation, "Create Task")
      
    If intRes = vbNo Then
      Cancel = False
    Else
      
    For Each Recipient In Item.Recipients
        strRecip = strRecip & vbCrLf & Recipient.Address
    Next Recipient

Debug.Print Item.Subject
        
With objTask

    .Body = strRecip & vbCrLf & Item.Body
    .Subject = Item.Subject
    .StartDate = Item.ReceivedTime
' Can use Now + nn for the start and/or due dates
 '   .DueDate = Now + 10
 '   .StartDate = Now + 9

    .ReminderSet = True
    .ReminderTime = Now + 2 + #9:00:00 AM#
' alternately, use the due date to set the reminder:
'   .ReminderTime = .DueDate - 2 + #2:00:00 PM#

    .Attachments.Add Item
    .Save
End With

End If

Set Item = Nothing
End Sub

Add the Recipient Display name to the task

This version of the code adds the recipients name to the task. You can use the full name or the first word in their name (hopefully it's the first name)

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    
Dim intRes As Integer
Dim strMsg As String
Dim objTask As TaskItem
Set objTask = Application.CreateItem(olTaskItem)
Dim strRecip As String

 strMsg = "Do you want to create a task for this message?"
 intRes = MsgBox(strMsg, vbYesNo + vbExclamation, "Create Task")
      
    If intRes = vbNo Then
      Cancel = False
    Else
 ' get the name, not the email address     
    For Each Recipient In Item.Recipients
        strRecip = strRecip & vbCrLf & Recipient.Name
    Next Recipient
' get the first name in the display name
StrSplit = Split(strRecip, " ")

With objTask
    .Body = strRecip & vbCrLf & Item.Body
    .Subject = StrSplit(0) & ": " & Item.Subject
    .StartDate = Item.ReceivedTime
' Can use Now + nn for the start and/or due dates
 '   .DueDate = Now + 10
 '   .StartDate = Now + 9

    .ReminderSet = True
    .ReminderTime = Date + 2 + #9:00:00 AM#

' alternately, use the due date to set the reminder:
'   .ReminderTime = .DueDate - 2 + #2:00:00 PM#

    .Save
End With

    Cancel = False
      
    End If

Set objTask = Nothing
    
End Sub

Video Tutorial

This tutorial shows how to add the macro to Outlook and use it.

How to use the Macro

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. If Outlook tells you it needs to be restarted, close and reopen Outlook. Note: after you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Now open the VBA Editor by pressing Alt+F11 on your keyboard.

To use the macro code in ThisOutlookSession:

  1. Expand Project1 and double click on ThisOutlookSession.
  2. Copy then paste the macro into ThisOutlookSession. (Click within the code, Select All using Ctrl+A, Ctrl+C to copy, Ctrl+V to paste.)

Application_Startup macros run when Outlook starts. If you are using an Application_Startup macro you can test the macro without restarting Outlook by clicking in the first line of the Application_Startup macro then clicking the Run button on the toolbar or pressing F8.

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 Task or Appointment and Insert Selected Text
  • Create Tasks from Email and move to different Task folders
  • Replicate GTD: Create a task after sending a message
Automatically create a task when sending a message was last modified: February 13th, 2019 by Diane Poremsky

Related Posts:

  • Use VBA to check Outlook's outgoing messages for attachments and cance
    Do you want to send an attachment?
  • A macro that checks the number of recipients on an outgoing Outlook me
    Check messages you send for number of recipients
  • Create a Series of Tasks Leading up to an Appointment
  • Create a Task from an Email using a Rule

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
53 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Suresh Babu
May 27, 2023 1:16 am

Hi Diane,

strMsg = strMsg & "Please find the pay slip of April 2023 attached." & vbcrlf & vbcrlf

I'm using the the above statement in the vbscript (notepad) for sending bulk mailers....kindly let me know how to choose font color

0
0
Reply
James Ziobro
August 17, 2022 10:43 am

Hello Diane:

This macro has been working great, however, recently the macro has stopped after this step:

  'removes your signature from the top of the Forward
  If objDoc.Bookmarks.Exists("_MailAutoSig") Then
  Set oBookmark = objDoc.Bookmarks("_MailAutoSig")
    oBookmark.Select
    objDoc.Windows(1).Selection.Delete
   End If

Any ideas on what it could be?

0
0
Reply
Diane Poremsky
Author
Reply to  James Ziobro
August 17, 2022 4:56 pm

Any error messages? Does it work if you remove that line?

If the bookmark doesn't exist, it should end, not error, so it shouldn't be that line causing the error.

0
0
Reply
James
April 25, 2022 10:44 am

Hello Diane - is there a way to NOT have this run when responding to a meeting (accepting, tentative, decline). I love this macro and however just wondering if there is a work around for meetings.

0
0
Reply
Diane Poremsky
Author
Reply to  James
April 25, 2022 3:23 pm

Yes, use an if statement as the first line -
if instr(1, item.messageclass, "IPM.Meeting") > 0 then exit sub

1
0
Reply
James Ziobro
Reply to  Diane Poremsky
April 25, 2022 4:00 pm

Diana - worked like a charm!!! Thanks so much.

0
0
Reply
Michael
July 31, 2020 8:15 pm

Hi,

I'm trying to use the Add Sent Message as Attachment macro however i'm getting the below error for the second line of the code:

Compile error:
Invalid attribute in Sub or Function

Private WithEvents objItems As Outlook.Items

I'm currently using Outlook 2013. Are you able to help correct the VBA?

0
0
Reply
D K
July 10, 2020 12:27 pm

I am also using your code here in order to create tasks from an email and automatically assign the task to a specified task folder. Is there a way to combine the two? I'm hoping to get two prompts whenever an email is sent: first prompt asks if I want to create a task (this is accomplished via your code above), and the 2nd prompt asks the user to select the desired task folder (for me, the folders are 'Action', 'Waiting', and 'Someday').

0
0
Reply
Diane Poremsky
Author
Reply to  D K
July 31, 2020 10:46 pm

Yes, you can do that.
the prompt would get the tFolder variable
Set taskFolder = Ns.GetDefaultFolder(olFolderTasks).Folders(tFolder)

0
0
Reply
Franz-Josef Knelangen
February 8, 2019 6:00 am

Just correcting myself: The information I want to add should go to the subject of the task, not of the sent message. I'd like to see tasks like:

Recipient.Firstname - Subject of my sent e-mail MM/DD
David - Finalize Proposal on XYZ 02/09

Then I would have a nice list to talk about all things I have to talk about with David :-)

0
0
Reply
Diane Poremsky
Author
Reply to  Franz-Josef Knelangen
February 12, 2019 11:42 pm

Getting just the first name is tough - you can easily get the display name and could split it at the first space, keeping the first segment, but it wont necessarily be the first name.

To get the first name, you could do a look up of the contact and take it from the contact. I have some code on the site that does a contact lookup for new messages (to add categories to the message) so its just a matter of putting the lookup code into this code.

This will get the first word in the display name:
For Each Recipient In Item.Recipients
strRecip = strRecip & vbCrLf & Recipient.Name
Next Recipient
StrSplit = Split(strRecip, " ")
With objTask
.Body = strRecip & vbCrLf & Item.Body
.Subject = StrSplit(0) & " " & Item.Subject

0
0
Reply
Franz-Josef Knelangen
February 8, 2019 5:34 am

Hi Diane,

thank you for providing this handy macro. I used the version with the date-added subject, and I'd like to add the recipient's name to the subject string, if possible, first name only. Adding "& Recipient.Name" to the subject line seems not to be sufficient, and that's already the end of my VBA knowledge. Could you help me out here?

Cheers,
Franz-Josef

0
0
Reply
daivd thompson
September 12, 2018 9:24 am

Hi Diane,

I think there might be another comment pending for your revierw. I promise this is the last request!

Cheers,

David

0
0
Reply
Diane Poremsky
Author
Reply to  daivd thompson
September 12, 2018 12:13 pm

>> I promise this is the last request!
I'll hold you to that. LOL

(Yes, I'm way behind in answering comments.)

1
0
Reply

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

Latest EMO: Vol. 30 Issue 34

Subscribe to Exchange Messaging Outlook






Support Services

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

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • Mail Templates in Outlook for Windows (and Web)
  • How to Remove the Primary Account from Outlook
  • Disable "Always ask before opening" Dialog
  • Adjusting Outlook's Zoom Setting in Email
  • This operation has been cancelled due to restrictions
  • Reset the New Outlook Profile
  • How to Hide or Delete Outlook's Default Folders
  • Removing Suggested Accounts in New Outlook
  • Change Outlook's Programmatic Access Options
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
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

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

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