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
July 20th, 2007 at 3:20 pm
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.
July 20th, 2007 at 3:21 pm
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.
July 21st, 2007 at 7:31 pm
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.
August 10th, 2007 at 5:20 am
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?
August 11th, 2007 at 12:27 pm
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.
December 5th, 2007 at 11:56 pm
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,
August 21st, 2008 at 3:27 am
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.
August 21st, 2008 at 10:31 pm
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/