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