shahine.com/omar/

homepage | Send mail to the author(s) contact

yet another Microsoft blogger

# Wednesday, August 02, 2006

Getting Things Done in Outlook 2007

Simon has a really good post on some simple macros you can create for Outlook 2007 for us GTD users. Personally I've got a simple "Next Action" button that executes the following VBA Script (Ugh I hate VBA).

Mine is a hybrid of his and one I created. The difference is that the first time you run mine it will create a toolbar button for itself and when you create a task it will open the task so that you can make edits like add a due date and subject to be more descriptive. It also trims "Re: " from the subject of the email.

Public Sub CreateNextAction()
    Dim olExp As Outlook.Explorer
    Dim myolApp As Outlook.Application
    Dim myNamespace As Outlook.NameSpace
    Dim myTasks As Outlook.Folder
    Dim myFolder As Outlook.Folder
    Set myolApp = Outlook.CreateObject("Outlook.Application")
    Set myolExp = myolApp.ActiveExplorer
    Set myNamespace = myolApp.GetNamespace("MAPI")
    Set myTasks = myNamespace.GetDefaultFolder(olFolderTasks)
    ' check for the toolbar button
    Set myobjCB = myolExp.CommandBars.item("Standard")
    On Error GoTo MyError
    Set objNA = myobjCB.Controls("&Next Action")
    On Error Resume Next
    
    Dim cntSelection As Integer
    cntSelection = myolExp.Selection.Count
    
    For i = 1 To cntSelection
        Dim item As MailItem
        Set item = myolExp.Selection.item(1)
        item.ShowCategoriesDialog
        Set myTask = item.Move(myTasks)
        subject = myTask.subject
        subject = Replace(subject, "RE: ", "")
        subject = Replace(subject, "Re: ", "")
        myTask.subject = subject
        myTask.Save
        myTask.Display
    Next
    
    Exit Sub
MyError:
        Set objNA = myobjCB.Controls.Add(msoControlButton)
        objNA.Caption = "&Next Action"
        objNA.FaceId = 7264
        objNA.Style = msoButtonIconAndCaption
        objNA.OnAction = "CreateNextAction"
        objNA.BeginGroup = True
        objNA.TooltipText = "Create a Next Action task from this E-mail"
End Sub

 

Tuesday, August 29, 2006 11:04:00 PM (Pacific Daylight Time, UTC-07:00)
To make this work on outlook 2003:

1. line 13: change
Dim myTasks As Outlook.Folder
To
Dim myTasks As Outlook.MAPIFolder

2. line 14: change
Dim myFolder As Outlook.Folder
To
Dim myFolder As Outlook.MAPIFolder

Tuesday, June 12, 2007 10:51:01 PM (Pacific Daylight Time, UTC-07:00)
I tried to run this in Outlook 2007, but I get an error:

Run-time error '429':

ActiveX component can't create object

I've digitally signed the macro so that it would be trusted. Any ideas?
Michael
Comments are closed.