Forum

  • If you are new to these Forums, please take a moment to register using the fields above.
Announcement Announcement Module
Collapse
No announcement yet.
Some VBA code for outlook to make action tasks from mails Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Some VBA code for outlook to make action tasks from mails

    Hi all,

    my probably most important inbox at work is my Outlook inbox . I wrote the following VBA routines to quickly generate an next action task from a mail or a waiting item.

    The code asumes that you have two folders called "@Action" and "@Waiting" within your inbox where you collect mails belonging to either a next action or where you wait for an answer.

    For next actions it asks you for a category to put the task in and suggest the mail subject as description. If you're ready it generates the task and moves the mail into the @Action folder.

    For waiting items it generates a task with category "waits" and description composed from sender name, subject and time received. It also moves it to the "@Waiting" folder.

    To use it open the VB Editor and copy the code into it. Then change the string YOURINBOXFOLDERHERE to your inbox folder (it's the string that is shown beside the icon in the folder view). Beside I added a button for each macro.

    Code:
    Sub CreateActionTaskfromMail()
    Dim oItem As Object
    Dim oTask As TaskItem
    Dim oPostfach As MAPIFolder
    Dim oFolder As MAPIFolder
    
    On Error GoTo TaskfromMail_Error
    
    Set oItem = Application.ActiveInspector.CurrentItem
    Set oPostfach = Application.GetNamespace("MAPI").Folders.Item(YOURINBOXFOLDERNAMEHERE)
    Set oFolder = oPostfach.Folders("@Action")
    
    Set oTask = Application.CreateItem(olTaskItem)
    
    With oTask
        .Subject = oItem.Subject
        .Body = oItem.SenderName & " " & oItem.Subject & " " &
    oItem.ReceivedTime
        .Importance = olImportanceNormal
        .ShowCategoriesDialog
        .Display
    End With
    
    oItem.Move oFolder
    
    Set oTask = Nothing
    Set oFolder = Nothing
    Set oPostfach = Nothing
    
    On Error GoTo 0
    Exit Sub
    
    TaskfromMail_Error:
        MsgBox "Error" & Err.Number & " (" & Err.Description & ") in procedure
    CreateActionTaskfromMail"
    End Sub
    
    Sub CreateWaitingTaskfromMail()
    Dim oItem As Object
    Dim oTask As TaskItem
    Dim oPostfach As MAPIFolder
    Dim oFolder As MAPIFolder
    
    On Error GoTo TaskfromMail_Error
    
    Set oItem = Application.ActiveInspector.CurrentItem
    Set oPostfach = Application.GetNamespace("MAPI").Folders.Item("Postfach -
    Stemplinger, Martin")
    Set oFolder = oPostfach.Folders("@Waiting")
    
    
    Set oTask = Application.CreateItem(olTaskItem)
    
    With oTask
        .Subject = "Mail: " & oItem.SenderName & " " & oItem.Subject & " " &
    oItem.ReceivedTime
        .Categories = "Waits"
        .Importance = olImportanceNormal
        .Save
    End With
    
    oItem.Move oFolder
    
    Set oTask = Nothing
    Set oFolder = Nothing
    Set oPostfach = Nothing
    
    On Error GoTo 0
    Exit Sub
    
    TaskfromMail_Error:
        MsgBox "Error" & Err.Number & " (" & Err.Description & ") in procedure
    CreateWaitingTaskfromMail"
    End Sub
    Disclaimer:
    • I tested the codee only with Outlook 2003 and german languge settings. If it doesn't work for you I will try to help you but will only partly be able to do so.

      I don't know if the outlook addin does something similar or not. I never saw it. Therefore I hope that I don't violate any intelectual properties.

      This code is free software and comes with absolutely no warranty. Use it at your own risk.

    Cheers
    Martin
Working...
X