PDA

View Full Version : Outlook Macro to handle consecutive tasks



xoff
02-12-2005, 10:55 PM
I have just posted in the netcentrics GTD Add-in support forum (suggestions/comments) a macro, which modifies GTD Police and automatically creates the next task after marking the previous one complete.

Though developed for the GTD Add-in, with slight modification it would work with a plain outlook setup as well.

Xoff

joeycan
02-14-2005, 08:12 AM
Nice tool I tested it out last nite great addition to a great macro.

trishacupra
02-14-2005, 11:48 PM
Could you please post the link to the netcentrics GTD Add-in support forum and/or post your macro at http://www.davidco.com/forum/viewtopic.php?t=1849?

Thanks - I look forward to being able to use it! :D

Trisha

xoff
02-15-2005, 02:59 AM
Could you please post the link to the netcentrics GTD Add-in support forum and/or post your macro at

The link is http://gtdsupport.netcentrics.com/forum/topic.asp?TOPIC_ID=514

I suggest using the link as you will need to replace a portion of GTD Police posted at:

http://gtdsupport.netcentrics.com/forum/topic.asp?TOPIC_ID=253

Good luck

Xoff

trishacupra
02-15-2005, 05:43 PM
Much appreciated. :D

trishacupra
02-16-2005, 12:32 AM
I'm inexperienced with macros and Visual Basic, but I love the whole concept and want to learn much more about how to program macros.

I'm having trouble with this macro and the Police macro.

I followed the instructions for the Police Macro except I put the modified This Outlook Session in first, then skip that in the Police instructions and pasted in the other modules (which are still called Module 2 etc as I don't know how to rename them, as indicated).

It's simply not working for me. There were some 'bugs' that Outlook didn't like when I pasted in the modified police code, and they were identified in red, I assume. I think it may have been a line break problem, because when I removed the line breaks, the red disappeared and it looked normal.

I've tested it and tested it, but it doesn't work.

I'd like to modify This Outlook Session to the normal police one to see if that works, but I can't figure out how to edit it now - it won't let me delete it or copy and paste over it. It was blank when I began.

Could someone please help me out, or point me in the direction of some good VB online help?

Thanks,

Trisha

vegheadjones
02-16-2005, 10:50 AM
Looks cool. If anyone with more VBA experience than me can modify this for use with out the GTD Outlook Add-In, please let me know!

xoff
02-16-2005, 07:11 PM
Looks cool. If anyone with more VBA experience than me can modify this for use with out the GTD Outlook Add-In, please let me know!

I am not too familiar with all the intricacies of GTD Police, however try removing line 130.

Let me know if this works out.

Xoff

xoff
02-16-2005, 07:17 PM
I followed the instructions for the Police Macro except I put the modified This Outlook Session in first, then skip that in the Police instructions and pasted in the other modules (which are still called Module 2 etc as I don't know how to rename them, as indicated).

Trish, Would suggest you start from scratch paste all the GTD Police code and then replace the THIS OUTLOOK SESSION text. No need to rename the modules.


There were some 'bugs' that Outlook didn't like when I pasted in the modified police code, and they were identified in red, I assume. I think it may have been a line break problem, because when I removed the line breaks, the red disappeared and it looked normal.

You are right , the posting broke off the lines. I will try to repost.

Xoff

trishacupra
02-16-2005, 09:23 PM
YIPPEE! It's working for me now!!! :D

This is so exciting - it's exactly what I've been wanting. This solves so many problems and saves so much time!

These macros are so great.

I've got the one which enables you to click the macro button to get a set of tasks you like to do on a daily basis - they're called 'Daily Disciplines'. It's a very neat, tidy way to handle routine tasks like that.

I'm also going to use the one that enables you to set a task to appear then disappear a set number of days. That's cool.

This modified Police macro is the king of GTD macros! David Allen ought to buy it off you to include in the GTD toolbar, it's so great!

I'm so excited, I'm off to do some project organizing!

Trisha :D

xoff
02-20-2005, 07:32 PM
This modified Police macro is the king of GTD macros! David Allen ought to buy it off you to include in the GTD toolbar, it's so great!

Trisha :D

Glad to hear that it is working for you and that you find it useful. The macro is a very simple change to GTD police. Bill Kratz deserves the credit for creating GTD Police.

Regards,

Xoff

AH
03-11-2005, 05:17 AM
Hi tried using this, wasn't working and deleted. But there is some code that will not delete in an Application-Sent Items window with the result that Intellisync won't work between Outlook and my Blackberry! Tried clearing BB and restarting but all my tasks are gone on the handheld! I'll try the macro again at some point but for now would just like to be able to synch Outlook to the blackberry. Can anyone please advise how I remove the code, sort this out! Many thanks Andrew

morberg
03-16-2005, 07:01 AM
Very nice. I couldn't get it to run without signing the project, which was quite easy following the instrucions here:

http://www.danevans.co.uk/vba/

However, I get a pop-up saying "A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this?" each time I run the script. Is there a way to either:

a) Always allow the script to access e-mail addresses (the drop-down has 10 minutes as max, which is way too low)
b) Have the script not access e-mail addresses?

I guess the pop-up is a feature to help disarm virii that use your address book to spread.

lilmagnus
03-16-2005, 12:01 PM
...
However, I get a pop-up saying "A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this?" each time I run the script. Is there a way to either:

a) Always allow the script to access e-mail addresses (the drop-down has 10 minutes as max, which is way too low)
b) Have the script not access e-mail addresses?

I guess the pop-up is a feature to help disarm virii that use your address book to spread.

I believe that is controlled through the Tools|Macros|Security settings. You may have to set it Low.

HTH

trishacupra
03-16-2005, 06:36 PM
That's how I got it to work for me when I set it up.

morberg
03-17-2005, 12:16 AM
...
However, I get a pop-up saying "A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this?" each time I run the script.

I believe that is controlled through the Tools|Macros|Security settings. You may have to set it Low.


Sorry, that didn't help with the pop-up. (Your fix takes care of the part I already addressed by signing the program myself.)

jhundley
03-17-2005, 08:11 AM
If any one is interested I modified GTD Police some time back to work with NAtara's Bonsai Basically following the Bonsai link from outlook back to the project in Bonsai and allowing the user to select another next action for the project

professor
04-07-2005, 03:16 AM
Hey, GTD Police and this mod are both fantastic (and essential) additions to the GTD add-in. Many thanks to all involved!!

But I was still bothered by the fact that the automatically created Next Actions are turned straight into tasks, and therefore bypass the InBox, and don't find their way into @Actions, @Deferred, which is where I tend to spend my time.

So, without in any way understanding VBA macros, I made one trivial change to your GTD Police mod - I change the new object to a MailObj (ie, a message) instead of a TaskObj. The result is that I automatically get a new message opening up, and I simply send it to myself to drop it in my InBox. This then gives me full control over what happens next, ie I can Action it, Defer it, Delegate it, Snooze it, File it or Delete it, and I now get the full use of the @Action, @Defered, etc views.

This is much better suited to the way I have got used to using GTD.

Now, if I knew what I was doing in VBA a little better, I'm sure I could figure out how to *automatically* get the created message into my InBox (with the proper Project value already set, instead of having to do the extra manual step of addressing and sending the message to myself.

What do you think? Is that a useful mod, or have I got the whole thing arse-up? If it's a worthwhile change, then can any VBA whiz figure out how to *automatically* drop the new message straight into my InBox?

Thanks HEAPS,
Lee (Sydney Australia)

professor
04-07-2005, 09:37 PM
Hi, I have done a bit more fiddling, and now have amended the GTD Police Macro (already amended as described in this thread), so that all automatically created items are saved as messages in the InBox, instead of as Tasks, so that the user can then make the determination of what to do with them (Action, Delegate, Defer, Delete, Snooze).

In the event that there is no automatically defined task (using the "- next task" convention), the macro now creates a blank message addressed to the user, so that the newly filled in task info again becomes a message in the InBox for appropriate treatment.

In short, I think that this slight change makes the entire GTD/Outlook process consistent, ie *everything* comes in via your InBox.

If anyone's interested, they are free to have my hacked code.

Thanks,
Lee.

gunns256
04-15-2005, 03:04 PM
Xoff:

I'd be glad if you would post your code here. I've seen it before on the Netcentrics forum, but they seem to have changed their policies in the last week, and now they only allow registered users to access the forums. The only way to register is to purchase the GTD addin. I'm not doing that yet. I'm implementing WHKratz's Projects-as-Contacts concept, and I have GTD police running in a way that Contacts access avoids the security call. If you're interested, I'll post my code.

Gunns256

SimonColes
04-17-2005, 04:35 AM
Xoff:

I'd be glad if you would post your code here. I've seen it before on the Netcentrics forum, but they seem to have changed their policies in the last week, and now they only allow registered users to access the forums. The only way to register is to purchase the GTD addin. I'm not doing that yet. I'm implementing WHKratz's Projects-as-Contacts concept, and I have GTD police running in a way that Contacts access avoids the security call. If you're interested, I'll post my code.

Gunns256

I'd be interested in using your code, gunns256. I'm also following William's projects-as-contacts approach.

Thanks,
Simon

Unregistered
04-21-2005, 01:46 PM
Gunns256:

Please post that code. I am using Contacts as Projects too, and would love to see it.

gunns256
04-22-2005, 06:17 PM
Many assumptions:

Assumes that you don't mind waiting until I have time till I read this forum again.

Assumes Projects folder containing contact items. You may use the Project form posted by WHK years ago. Or you can just start with contacts.

Assumes all projects are named with bracket enclosures [MyProject] and cannot contain commas [My Project, which I will do next]. (The commas screw up some convention in Outlook's name routines.)

Assumes that some projects contain lists of NAs on lines with heading "- " notice space.

Assumes existence of toolbar "Advanced".

Assumes familiarity with VB editor. Assumes tolerance of imperfect code. (This is still a work in progress.)

Assumes tolerance by xoff, whkratz, of modifications of their publicly posted code.

I think that's all the assumptions.

Purpose: GTD police, NA list in body field of ProjectContacts will create new NA on project completion, toolbar with 3 menus for tasks: Projects, Defer, Context.

There may be some trouble with wordwrapping code copied from this forum.

gunns256
04-22-2005, 06:18 PM
There are two sections of code to copy and paste: This section, to copy and paste into ThisOutlookSession, and another section, to c & p into a new module (mine is named Utilities).

' Module : ThisOutlookSession
' Description:
' Procedures : Application_Startup()
' objTaskItems_ItemChange(ByVal pobjItem As Object)

' Modified :
' 11/13/03 WHK
' Modified 4/16/2005 EFG
' --------------------------------------------------
Private WithEvents objTaskItems As Items

Private Sub Application_Quit()
Set objTaskItems = Nothing
End Sub

Private Sub Application_Startup()
On Error GoTo PROC_ERR
TestAddComboBoxToCommandBar 'adds 3 comboboxes to a commandbar named Advanced
'comboboxes are Projects, Defer, and Context
Set objTaskItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks).Items
'yes, that's the taskitems folder
'all these various outlook variables
'give me a pain in the ass. I'm
'hardcoding the whole thing.
PROC_EXIT:
Exit Sub

PROC_ERR:
'removed errorlog
Resume PROC_EXIT
End Sub
Private Sub objTaskItems_ItemChange(ByVal pobjItem As Object)
On Error GoTo PROC_ERR

Dim objNewTask As TaskItem 'will be new N/A task
Dim intAns As Integer 'input from msgbox
Dim objProj As ContactItem 'found in folder "Projects"
Dim strSubject As String 'will be subject of next action task
Dim strProject As String 'name of project
Dim strBody As String 'body field of found project, may contain formatted list of NAs
Dim posCR As Integer 'carriagereturn position, delimits NAs in body field of found project
If pobjItem.Links.Count = 0 Then Exit Sub 'no links, no project, nothing to do
If pobjItem.Links.Count = 1 And InStr(1, pobjItem.Links.Item(1).Name, "[") = 1 Then
'project names must be delimited with brackets [ProjectName]
'limited now to only project contacts, routine will fail if there are other contacts which are not projects
'project contacts are linked
strSubject = pobjItem.Subject 'allows use in msgbox with completion announcement
strProject = pobjItem.Links.Item(1).Name
'open a project's body field with list of NAs
Set objProj = Application.GetNamespace("mapi").Folders.Item(1).Folders("Projects").Items.Item(strProject)
strBody = objProj.Body
If pobjItem.Status = 2 Then 'that would be completed
intAns = MsgBox("You have completed a Project-related Task." _
& vbCrLf & "Task: " & strSubject & vbCrLf & "Project: " _
& strProject & vbCrLf & "Do you want to create a new Next Action for the Project?", _
36, "Next Action?")
End If
If intAns = 6 Then 'Not testing for anything else
Set objNewTask = pobjItem.Copy 'why not? It's already linked to the project, and probably in the right context
If Left(strBody, 1) = "-" Then '- dash/space will signify
'the beginning of a next action in the project body field
If InStr(strBody, vbCrLf) <> Empty Then
posCR = InStr(strBody, vbCrLf)
strSubject = Mid(strBody, 3, (posCR - 3))
strBody = Right(strBody, Len(strBody) - posCR - 1)
strBody = strBody & vbCrLf & "x " & strSubject
objProj.Body = strBody 'takes first line of body field, uses it, moves it to end with x
objProj.Save
Else
posCR = Len(strBody) 'just a 1 liner, cut, use, and replace
strSubject = Mid(strBody, 3, (posCR - 2))
strBody = "x " & strSubject
objProj.Body = strBody 'takes first line of body field, uses it, moves it to end with x
objProj.Save
End If
Else
strSubject = InputBox("Taskname?") 'no NAs in body field
End If
objNewTask.Subject = strSubject
objNewTask.Status = olTaskNotStarted
objNewTask.Display
End If
End If
Set objProj = Nothing
Set objNewTask = Nothing
Set pobjItem = Nothing
PROC_EXIT:
Exit Sub
PROC_ERR:
Resume PROC_EXIT
End Sub

gunns256
04-22-2005, 06:21 PM
Create new module, (mine is Utilities). Copy and paste:
Sub UpdateContext(objSel As Selection)
Dim objItem As Object
Dim mycategory As String
mycategory = Application.ActiveExplorer.CommandBars.Item("Advanced").Controls.Item("Context").Text
'MsgBox (mycategory)
Application.ActiveExplorer.CommandBars.Item("Advanced").Controls.Item("Context").Text = "Context"
For Each objItem In objSel
If objItem.Class = olTask Then
objItem.Categories = ""
objItem.Categories = mycategory
objItem.Save
Else
MsgBox (objItem.Class)
End If
Next
Set objItem = Nothing
End Sub

Sub UpdateDefer(objSel As Selection)
Dim objItem As Object
Dim strdeferdate As String
Dim mydate As Date
strdeferdate = Application.ActiveExplorer.CommandBars.Item("Advanced").Controls.Item("Defer").Text
Application.ActiveExplorer.CommandBars.Item("Advanced").Controls.Item("Defer").Text = "Defer"
'MsgBox (strdeferdate)
For Each objItem In objSel
If objItem.Class = olTask Then
If strdeferdate = "None" Then
objItem.DueDate = #1/1/4501# 'esoterica. look it up.
Else
mydate = objItem.DueDate
'these are good for me because I'm a teacher
If strdeferdate = "1 week" Then mydate = DateAdd("ww", 1, mydate)
If strdeferdate = "1 month" Then mydate = DateAdd("m", 1, mydate)
If strdeferdate = "End June" Then mydate = DateValue("6/25")
If strdeferdate = "End August" Then mydate = DateValue("8/25")
If mydate < Date Then mydate = mydate + 365
objItem.DueDate = mydate
End If
objItem.Save
Else
MsgBox (objItem.Class)
End If
Next
Set objItem = Nothing
End Sub
Sub UpdateProject(objSel As Selection)
Dim objItem As Object
Set mynamespace = Application.GetNamespace("MAPI")
Set myfolders = mynamespace.Folders
Set myfolder = myfolders.Item(1).Folders.Item("Projects")
strprojname = Application.ActiveExplorer.CommandBars.Item("Advanced").Controls.Item("Projects").Text
Application.ActiveExplorer.CommandBars.Item("Advanced").Controls.Item("Projects").Text = "Projects"
'MsgBox (strprojname)
If strprojname = "" Then
Exit Sub
End If

Set mycontact = myfolder.Items(strprojname)
For Each objItem In objSel
'If objItem.Class = olTask Then
objItem.Links.Add mycontact
objItem.Save
'End If
Next
Set objItem = Nothing
End Sub

Private Function SelectionAction()

Dim objSelection As Selection
Dim blnDoIt As Boolean
Dim intMaxItems As Integer
Dim intOKToExceedMax As Integer
Dim strMsg As String
intMaxItems = 5
Set objSelection = Application.ActiveExplorer.Selection
Select Case objSelection.Count
Case 0
strMsg = "No items were selected"
MsgBox strMsg, , "No selection"
blnDoIt = False
Case Is > intMaxItems
strMsg = "You selected " & _
objSelection.Count & " items. " & _
"Do you really want to process " & _
"that large a selection?"
intOKToExceedMax = MsgBox( _
Prompt:=strMsg, _
Buttons:=vbYesNo + vbDefaultButton2, _
Title:="Selection exceeds maximum")
If intOKToExceedMax = vbYes Then
blnDoIt = True
Else
blnDoIt = False
End If
Case Else
blnDoIt = True
End Select
If blnDoIt = True Then
If Application.ActiveExplorer.CommandBars.Item("Advanced").Controls.Item("Projects").Text <> "Projects" Then
Call UpdateProject(objSelection)
End If
If Application.ActiveExplorer.CommandBars.Item("Advanced").Controls.Item("Defer").Text <> "Defer" Then
Call UpdateDefer(objSelection)
End If
If Application.ActiveExplorer.CommandBars.Item("Advanced").Controls.Item("Context").Text <> "Context" Then
Call UpdateContext(objSelection)
End If
End If
Set objSelection = Nothing
'Set objApp = Nothing
End Function
Private Function AddComboBoxToCommandBar(ByVal strCommandBarName As String, _
ByVal strComboBoxCaption As String, _
ByRef strChoices() As String) As Boolean

' Purpose: Adds a combo box to a command bar.
' Accepts:
' strCommandBarName: The name of the command bar to add the combo box.
' strChoices(): An array of combo box choices.
' Returns: True if the combo box was successfully added to the command bar.

Dim objCommandBarControl As Office.CommandBarControl
Dim objCommandBarComboBox As Office.CommandBarComboBox
Dim varChoice As Variant

On Error GoTo AddComboBoxToCommandBar_Err
Application.ActiveExplorer.CommandBars.Item(strCom mandBarName).Visible = True
' Delete any previously-added instances of this combo box.
' Replace the next line of code with:
For Each objCommandBarControl In _
Application.ActiveExplorer.CommandBars.Item(strCom mandBarName).Controls
_
'<- For Outlook
' For Each objCommandBarControl In _
' Application.VBE.CommandBars.Item(strCommandBarName ).Controls _
<- For Visual Basic Editor
'For Each objCommandBarControl In Application.CommandBars.Item(strCommandBarName).Co ntrols

If objCommandBarControl.Caption = strComboBoxCaption Then

objCommandBarControl.Delete

End If

Next objCommandBarControl

' Create the combo box.
' Replace the next line of code with:
' Set objCommandBarComboBox = _
' Application.CommandBars.Item(strCommandBarName).Co ntrols.Add(msoControlComboBox) _
<- For Outlook
' Set objCommandBarComboBox = _
' Application.CommandBars.Item(strCommandBarName).Co ntrols.Add(msoControlComboBox) _
<- For Visual Basic Editor
Set objCommandBarComboBox = _
Application.ActiveExplorer.CommandBars.Item(strCom mandBarName).Controls.Add(msoControlComboBox)

objCommandBarComboBox.Caption = strComboBoxCaption

For Each varChoice In strChoices

objCommandBarComboBox.AddItem varChoice

Next varChoice
If strComboBoxCaption = "Projects" Then
objCommandBarComboBox.Text = "Projects"
objCommandBarComboBox.Width = 150
objCommandBarComboBox.OnAction = "SelectionAction"
End If
If strComboBoxCaption = "Defer" Then
objCommandBarComboBox.Text = "Defer"
objCommandBarComboBox.Width = 100
objCommandBarComboBox.OnAction = "SelectionAction"
End If
If strComboBoxCaption = "Context" Then
objCommandBarComboBox.Text = "Context"
objCommandBarComboBox.Width = 100
objCommandBarComboBox.OnAction = "SelectionAction"
End If
AddComboBoxToCommandBar_End:

AddComboBoxToCommandBar = True
Exit Function

AddComboBoxToCommandBar_Err:

AddComboBoxToCommandBar = False
MsgBox ("addcomboboxtocommandbar.error")

End Function
'called from This Outlook Session, adds comboboxes by calling AddComboBoxToCommandBar
Public Sub TestAddComboBoxToCommandBar()
Set mynamespace = Application.GetNamespace("MAPI")
Set myfolders = mynamespace.Folders
Set myfolder = myfolders.Item(1).Folders.Item("Projects")
Dim projcollection As Collection
Dim strChoices() As String
Set myitems = myfolder.Items
myitems.Sort "[FullName]"
ReDim strChoices(myfolder.Items.Count + 2)
strChoices(1) = "Projects"
'strChoices(2) = "Refresh"
For I = 1 To myfolder.Items.Count
strChoices(I + 1) = myitems.Item(I).FullName
Next I
Call AddComboBoxToCommandBar("Advanced", "Projects", strChoices)
Set projcollection = Nothing
ReDim strChoices(6)
strChoices(1) = "Defer"
strChoices(2) = "1 week"
strChoices(3) = "1 month"
strChoices(4) = "End June"
strChoices(5) = "End August"
strChoices(6) = "None"
Call AddComboBoxToCommandBar("Advanced", "Defer", strChoices)
ReDim strChoices(11)
strChoices(1) = "Context"
strChoices(2) = "@Agenda"
strChoices(3) = "@Computer"
strChoices(4) = "@Errand"
strChoices(5) = "@Home"
strChoices(6) = "@Phone"
strChoices(7) = "@School"
strChoices(8) = "@Transfer"
strChoices(9) = "@Waiting"
strChoices(10) = "<Someday"
strChoices(11) = ">Goals"
Call AddComboBoxToCommandBar("Advanced", "Context", strChoices)
Set myfolder = Nothing
Set myfolders = Nothing
Set mynamespace = Nothing
End Sub

gunns256
04-22-2005, 06:23 PM
I hope you find this useful. 3 posts, read assumptions in first post.

Good luck!

gunns256

JaFi
06-30-2005, 04:52 PM
Yes, post your code, I'm collecting the various flavors of macros and will post a list when it's as complete as it will get.
--jf


Hi, I have done a bit more fiddling, and now have amended the GTD Police Macro (already amended as described in this thread), so that all automatically created items are saved as messages in the InBox, instead of as Tasks, so that the user can then make the determination of what to do with them (Action, Delegate, Defer, Delete, Snooze).

In the event that there is no automatically defined task (using the "- next task" convention), the macro now creates a blank message addressed to the user, so that the newly filled in task info again becomes a message in the InBox for appropriate treatment.

In short, I think that this slight change makes the entire GTD/Outlook process consistent, ie *everything* comes in via your InBox.

If anyone's interested, they are free to have my hacked code.

Thanks,
Lee.

benjy_green
09-27-2005, 02:22 PM
The link is http://gtdsupport.netcentrics.com/forum/topic.asp?TOPIC_ID=514

I suggest using the link as you will need to replace a portion of GTD Police posted at:

http://gtdsupport.netcentrics.com/forum/topic.asp?TOPIC_ID=253

Good luck

Xoff

These links no longer work - Where can I access this code?
Does it work when using the Taskline form?
Thanks
Ben

fionamac
03-17-2006, 04:00 PM
Hi all

Have been using modified GTD police code which I love (thx to messrs Kratz and Xoff!). As an incentive to do the weekly review, I add in all the @ actions beside the next consecutive tasks like those listed below during the review (so I really only have to think once a week). For example consecutive actions in the body of the task might be:

- Ring Jane for luke's email address @calls
- Email Luke about a meeting @computer
- Create agenda for meeting with luke @anywhere
...

but then during the week when I complete the task prior to 'Ring Jane..." the next task has '- Ring Jane for luke's email address @calls' in the subject line and I cut and paste @calls into Actions.

I have been trying to get the '@ calls' to go straight into the Action field - by trying to understand the code of the VBA masters - without success - Any ideas people??? I'll persevere and share the code if I crack it!!!

Regards, Fiona