Last reviewed on May 22, 2013   —  4 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.



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



Comments

  1. Peter says

    Hello I have problem after running this macro in outlook 2013. In fact it works but when I'm restarting outlook runtime error occurs -2146959355 (80080005), nevertheless when I open outlook macro works fine but I have problem with outlook folders that do not work properly.

    Do you have any hint how to fix this problem?
    thanks in advance

    • Diane PoremskyDiane Poremsky says

      Click Debug on the error dialog - which line is highlighted in yellow? That error generally means an object that is referenced in the code can't be found. Nothing in the code should trigger that error though.

  2. Nick says

    I'm getting a similar error on a different VBA. The bit that hits yellow is: Set myOlApp = CreateObject("Outlook.Application")

    • Diane PoremskyDiane Poremsky says

      Is the macro in thisoutlooksession and is Public WithEvents myOlApp As Outlook.Application the first line?

Leave a Reply

Please post long or more complicated questions at OutlookForums by Slipstick.com.

If the Post Comment button disappears, press your Tab key.