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.
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.
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:
- Set macro security to low.
- Open the VBA Editor (Alt+F11)
- Expand Project1 to find ThisOutlookSession
- 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.
Public WithEvents myOlApp As Outlook.Application Private Sub Application_Startup() Initialize_handler End Sub Public Sub Initialize_handler() Set myOlApp = CreateObject("Outlook.Application") End Sub Private Sub myOlApp_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 .ReminderSet = True .ReminderTime = DateSerial(Year(Now), Month(Now), Day(Now + 2)) + #9:00:00 AM# .Save End With Cancel = False End If Set objTask = Nothing End Sub
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:
- Expand Project1 and double click on ThisOutlookSession.
- 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.