Recent Posts

Categories

Archives

Calendar

November 2008
M T W T F S S
« Jul    
 12
3456789
10111213141516
17181920212223
24252627282930

Search


Meta

Outlook Item to Task Macro

The following macros convert outlook items to tasks with different categories. Based on this blog post which in turn is based on this one.

  • The item body is copied to the task body and the item itself is added as an attachment.
  • If multiple items are selected, multiple tasks will be created.
  • Created tasks are left open for editing.
  • I am in two minds about deleting the item after the task is created and have decided against it at the moment.
  • It appears that OL 2007 does not allow shortcut keys to be assigned to macros .

Public Sub CreateInboxTaskFromItem()
    CreateCatagorisedTaskFromItem (”2 inbox”)
End Sub

Public Sub CreateWaitingTaskFromItem()
    CreateCatagorisedTaskFromItem (”2 waiting for”)
End Sub

Public Sub CreateSomedayTaskFromItem()
    CreateCatagorisedTaskFromItem (”2 someday maybe”)
End Sub

Public Sub CreateTaskFromItem()
    CreateCatagorisedTaskFromItem (”")
End Sub

Private Sub CreateCatagorisedTaskFromItem(catagory As String)

  Dim olTask As Outlook.TaskItem
  Dim olItem As Object
  Dim olExp As Outlook.Explorer
  Dim fldCurrent As Outlook.MAPIFolder
  Dim olApp As Outlook.Application
 
  Set olApp = Outlook.CreateObject(”Outlook.Application”)
  Set olExp = olApp.ActiveExplorer
  Set fldCurrent = olExp.CurrentFolder
 
  Dim cntSelection As Integer
  cntSelection = olExp.Selection.Count
 
  For i = 1 To cntSelection
    Set olTask = olApp.CreateItem(olTaskItem)
    Set olItem = olExp.Selection.Item(i)
    olTask.Attachments.Add olItem
    olTask.Body = olTask.Body + olItem.Body
    If catagory = “2 waiting for” Then
        olTask.Subject = olItem.SenderName & “: ” & olItem.Subject
    Else
        olTask.Subject = olItem.Subject
    End If
    olTask.Categories = catagory
    ‘olItem.Delete
    olTask.Display
    olTask.Save
  Next
 
End Sub

8 Responses to “Outlook Item to Task Macro”

  1. Sandra Says:

    Just curious - how would you specify a form to use when creating the task? I have tried the original version of this from Lemson, but even thought my task default form (customized) is set correctly in Outlook, the new task doesn’t use it.

    Thanks.

  2. Sandra Says:

    I have tried this macro from Lemson. Question: how would I specify a custom form to be used in tasks? I have the default form in tasks set correctly in Outlook, but the Macro doesn’t use it.

    Thanks.

  3. John Plummer Says:

    Hi Sandra,
    I do not use custom forms in Outlook but the best outlook resource on the web is probably http://www.outlookcode.com/. There is a good community there and someone should be able to help you.

  4. Charles Says:

    Great Macro! How can I have the Macro create a task from the message I have open instead of what is selected in the table view?

  5. John Plummer Says:

    Hi Charles,
    This is untested but I would guess that the following function should do it:

    Private Sub CreateCatagorisedTaskFromOpenItem(catagory As String)

    Dim olTask As Outlook.TaskItem
    Dim olItem As Object
    Dim olApp As Outlook.Application
    Dim olIns As Outlook.Inspector

    Set olApp = Outlook.CreateObject(”Outlook.Application”)
    Set olIns = olApp.ActiveInspector

    Set olTask = olApp.CreateItem(olTaskItem)
    Set olItem = olIns.CurrentItem
    olTask.Attachments.Add olItem
    olTask.Body = olTask.Body + olItem.Body
    If catagory = “2 waiting for” Then
    olTask.Subject = olItem.SenderName & “: ” & olItem.Subject
    Else
    olTask.Subject = olItem.Subject
    End If
    olTask.Categories = catagory
    ‘olItem.Delete
    olTask.Display
    olTask.Save

    End Sub

    Then Change the calling functions to call CreateCatagorisedTaskFromOpenItem rather than CreateCatagorisedTaskFromItem.

  6. Yasmeen Says:

    John,

    Excellent macro, I’ve been looking for something like this.

    Just some feedback: your code causes Outlook 2003 to prompt with the “Allow access to” pop-up, which is annoying.

    To prevent that from happening, you need to change:

    Set olApp = Outlook.CreateObject(”Outlook.Application”)

    to:

    Set olApp = Application

    The CreateObject caused that issue.

    Cheers,

  7. Dwayne Says:

    John I copied your code into outlook2007. Each time I run one of the macros I get a syntax error on either line around 2 - 13 depending on the macro. Any suggestions? Thanks.

  8. John Plummer Says:

    Hi Dwayne,
    I would check that copying and pasting from html has not introduced and character substitutions, especially the double quotes.
    It may be worth copying and pasting into notepad then copying and pasting from there as a text editor as an intermediate stage can often weed out things like smart quotes.

    If that doesn’t work it may be worth posting the question on http://www.outlookcode.com/

Leave a Reply