View Full Version : dragging tasks in outlook
ameasha
11-29-2004, 01:46 PM
I do a massive amount of volunteer management in my line of work, and one of the most useful techniques in GTD for me is the @waitingfor list. I use Outlook and drag and drop my sent e-mails to the task list to create my @waitingfor tasks. Most of the time I will be waiting for responses from multiple people.
Does anyone have a trick or tip to share on creating multiple tasks from one sent e-mail without dragging and dropping multiple times? Sounds like a small thing, but I think it will make a big difference in my system if I can work out this kink.
Thank you!
whkratz
11-29-2004, 09:15 PM
Here's a very rough draft of a macro that may do what you want. This macro creates an "@waiting for" Task for each Recipient of a currently selected e-mail (in either the current Inspector or Explorer). As it stands in this rough draft, the macro: Saves the Tasks to the default Tasks folder. If you save these @waiting for Tasks elsewhere, we'll have to modify the code accordingly.
Sets the Task Reminder for one week hence. If you want a different interval, we'll modify accordingly or set up some kind of choice for the interval.
Also sets the Due Date one week hence.To test the basic functionality of this macro, copy and paste the code below into a new Module in your Outlook Visual Basic Editor. Then select an E-Mail message and run the "AtWaitingForTasksFromEmail" macro (Alt + F8). You may get a Security warning. Allow access for a minute at the security prompt, and check out the results. Report back so that we can clean up the code to suit your needs.
Regards....Bill Kratz
Here's the code:
Option Explicit
Sub AtWaitingForTasksFromEmail()
' Comments :
' Parameters: -
' Modified :
'
' --------------------------------------------------
Dim objTask As Outlook.TaskItem
Dim objApp As Outlook.Application
Dim objCurrentItem As Object
Dim objRecips As Outlook.Recipients
Dim objRecip As Outlook.Recipient
Set objApp = Outlook.CreateObject("Outlook.Application")
Set objCurrentItem = GetCurrentItem()
If objCurrentItem.Class = olMail Then
Set objRecips = objCurrentItem.Recipients
For Each objRecip In objRecips
Set objTask = objApp.CreateItem(olTaskItem)
objTask.Attachments.Add objCurrentItem
objTask.Subject = "@Waiting For " & objRecip & " Regarding " & objCurrentItem.Subject
objTask.DueDate = Date + 7
objTask.ReminderSet = True
objTask.ReminderTime = DateAdd("d", 7, Now)
objTask.Display
objTask.Save
Next
Else:
MsgBox "Oops!!! This macro only works with Mail Items."
Exit Sub
End If
End Sub
Function GetCurrentItem() As Object
' Comments :
' Parameters: -
' Returns : Object -
' Modified :
'
' --------------------------------------------------
Dim objApp As Application
Dim objSel As Selection
Dim objCurrentItem As Object
Set objApp = CreateObject("Outlook.Application")
Select Case objApp.ActiveWindow.Class
Case olExplorer
Set objSel = objApp.ActiveExplorer.Selection
If objSel.Count > 0 Then
Set objCurrentItem = objSel.item(1)
End If
Case olInspector
Set objCurrentItem = objApp.ActiveInspector.CurrentItem
Case Else
End Select
Set GetCurrentItem = objCurrentItem
Set objCurrentItem = Nothing
Set objSel = Nothing
Set objApp = Nothing
End Function
8)
ameasha
11-30-2004, 06:27 AM
I am absolutely blown away by the generosity of your response. The macro works GREAT. How would I change it to make the task file under my @WaitingFor category?
THANK YOU
whkratz
11-30-2004, 07:22 AM
In between these two lines
objTask.ReminderTime = DateAdd("d", 7, Now)
objTask.Display
Add the following line
objTask.Categories = "@WaitingFor"
As I mentioned in the first post, this is a rough draft, and there are a few things that should be cleaned up. Use the macro for a bit, and see if anything else should be changed or added. After we've fine tuned the functionality, we'll do the housekeeping.
Regards.....Bill Kratz
ameasha
11-30-2004, 07:30 AM
I can't thank you enough. I will use the macro and let you know if additional tweaks would be useful. Thank you for lending your expertise!!
Amanda
ameasha
11-30-2004, 07:50 AM
Bill:
Another tweak that would be ultra useful, but I have no idea how to do it:
Can we put today's date (in the "11.30.04" format) at the end of the task? So it would say "Amanda Regarding Tweak 11.30.04"
Thanks!
Amanda
whkratz
11-30-2004, 08:07 AM
Replace
objTask.Subject = "@Waiting For " & objRecip & " Regarding " & objCurrentItem.Subject
With
objTask.Subject = "@Waiting For " & objRecip & " Regarding " & objCurrentItem.Subject & " " & Format(Now, "mm.dd.yy")
Best Regards.....Bill Kratz
ameasha
11-30-2004, 08:12 AM
Bill -
Thank you!! :!:
Amanda
bdavidson
11-30-2004, 09:49 AM
Bill,
How complex a macro would be required to:
1. Scan my Inbox for messages sent by me, where I am not on the To: or Cc: line (i.e. a Bcc: to myself, which is how I manage delegations for the @WF list),
2. Create a task in the task folder with "<To Recipient(s) name(s)> - <Sent Date> - <Subject>" as the subject, category = @Waiting For, task body = message body,
3. Delete the original message in the inbox upon successful task creation.
4. Avoid the Outlook security prompt by using Redemption.
This would let me bcc myself on delegated tasks, while not having to manage the bcc emails directly when I receive them, since I always perform the same activity (right-click drag to tasks, insert names and date before subject, Category = @Waiting For, save and close).
Let me know what you think. This would be a killer app for me. I may try tweaking your code below, but I really don't understand how to properly use Redemption SafeMailItems to avoid the security prompts.
Thanks for listening,
Brian
tfadams
11-30-2004, 11:42 AM
Here's a very rough draft of a macro that may do what you want.
Great to see you back, Bill!
- Todd
ameasha
11-30-2004, 01:28 PM
Bill:
Is there a way to make the macro only save tasks for people in the TO line and not the CC line?
Amanda
bdavidson
11-30-2004, 07:36 PM
OK, Bill's code really inspired me to work on this. Below is my revision to his original code. This code will bypass the Outlook security prompts if you have downloaded and installed Redemption (http://www.dimastr.com/redemption/). It will take the currently selected message and create a Waiting For task for each person in the To line only, formatted as "Name - Date Sent - Subject", category as "@Waiting For", email body in Task notes.
Option Explicit
Sub AtWaitingForTasksFromEmail()
' Comments :
' Parameters: -
' Modified : 12/06/2004 - B.Davidson
'
' --------------------------------------------------
Dim objTask As Outlook.TaskItem
Dim objApp As Outlook.Application
Dim objCurrentItem As Object 'currently selected item in Outlook
Dim objRecips As SafeRecipients 'All recipients on message
Dim objRecip As SafeRecipient 'Current recipient
Dim objWFMail 'for Redemption mail item
Dim objForward 'for Redemption mail item for getting mail body with headers
Set objApp = Outlook.CreateObject("Outlook.Application")
Set objCurrentItem = GetCurrentItem() 'get currently selected item
Set objWFMail = CreateObject("Redemption.SafeMailItem") 'use Redemption to bypass the security prompts
objWFMail.Item = objCurrentItem 'use Redemption to bypass the security prompts
If objWFMail.Class = olMail Then 'only run if the current item is a mail message
Set objRecips = objWFMail.Recipients 'get all the recipients on the message (To, CC)
For Each objRecip In objRecips 'check all the recipients
If objRecip.Type = olTo Then 'if the current recipient is on the To line, create a @WF task
Set objTask = objApp.CreateItem(olTaskItem) 'create a blank task
'Set the subject per the DA white paper format (Name, Date, Subject
objTask.Subject = objRecip.Name & " - " & Format(objWFMail.SentOn, "mm/dd/yyyy") & " - " & objWFMail.Subject
'Create a forwarded copy of the message to preserve the headers in the @WF task
Set objForward = CreateObject("Redemption.SafeMailItem")
objForward.Item = objCurrentItem.Forward
objForward.Save 'save the draft forward message so redemption can see it
objTask.Body = objForward.Body '
objForward.Delete 'delete the draft message (no longer needed)
objTask.Categories = "@Waiting For" 'Change to whatever category you like
objTask.Save 'save your work!
End If 'objRecip.Type = olTo
Next 'go process the next recipient
Else:
MsgBox "Oops!!! This macro only works with Mail Items."
Exit Sub
End If
'Variable cleanup
Set objTask = Nothing
Set objForward = Nothing
Set objRecip = Nothing
Set objRecips = Nothing
Set objWFMail = Nothing
Set objCurrentItem = Nothing
Set objApp = Nothing
End Sub
Function GetCurrentItem() As Object
' Comments :
' Parameters: -
' Returns : Object -
' Modified :
'
' --------------------------------------------------
Dim objApp As Application
Dim objSel As Selection
Dim objCurrentItem As Object
Set objApp = CreateObject("Outlook.Application")
Select Case objApp.ActiveWindow.Class
Case olExplorer
Set objSel = objApp.ActiveExplorer.Selection
If objSel.Count > 0 Then
Set objCurrentItem = objSel.Item(1)
End If
Case olInspector
Set objCurrentItem = objApp.ActiveInspector.CurrentItem
Case Else
End Select
Set GetCurrentItem = objCurrentItem
Set objCurrentItem = Nothing
Set objSel = Nothing
Set objApp = Nothing
End Function
I've also created a version that can be used in conjunction with an Outlook rule (with "Run a script" as the rule's action). My rule checks messages as they arrive, and if I'm not in the To: line (I've either CCed or BCCed myself), run the script "WaitingForFromEmail" and delete the message.
Public Sub WaitingForFromEmail(MyMail As Outlook.MailItem)
' Comments :
' Parameters: -
' Modified : 12/06/2004 - B.Davidson
'
' --------------------------------------------------
Dim objTask As Outlook.TaskItem
Dim objApp As Outlook.Application
Dim objRecips As SafeRecipients 'All recipients on message
Dim objRecip As SafeRecipient 'Current recipient
Dim objWFMail 'for Redemption mail item
Dim objForward 'for Redemption mail item for getting mail body with headers
Set objApp = Outlook.CreateObject("Outlook.Application")
Set objWFMail = CreateObject("Redemption.SafeMailItem") 'use Redemption to bypass the security prompts
objWFMail.Item = MyMail 'use Redemption to bypass the security prompts
If objWFMail.Class = olMail Then 'only run if the current item is a mail message
Set objRecips = objWFMail.Recipients 'get all the recipients on the message (To, CC)
For Each objRecip In objRecips 'check all the recipients
If objRecip.Type = olTo Then 'if the current recipient is on the To line, create a @WF task
Set objTask = objApp.CreateItem(olTaskItem) 'create a blank task
'Set the subject per the DA white paper format (Name, Date, Subject
objTask.Subject = objRecip.Name & " - " & Format(objWFMail.SentOn, "mm/dd/yyyy") & " - " & objWFMail.Subject
'Create a forwarded copy of the message to preserve the headers in the @WF task
Set objForward = CreateObject("Redemption.SafeMailItem")
objForward.Item = MyMail.Forward
objForward.Save 'save the draft forward message so redemption can see it
objTask.Body = objForward.Body 'copy the email body with basic headers to task note field
objForward.Delete 'delete the draft message (no longer needed)
objTask.Categories = "@Waiting For" 'Change to whatever category you like
objTask.Save 'save your work!
End If 'objRecip.Type = olTo
Next 'go process the next recipient
Else:
Exit Sub
End If
'Variable cleanup
Set objTask = Nothing
Set objForward = Nothing
Set objRecip = Nothing
Set objRecips = Nothing
Set objWFMail = Nothing
Set objApp = Nothing
End Sub
I don't know how clean or efficient this code is, but it does what I want without the instability of the GTD Add-in and extra overhead.
I welcome any further ideas or inputs with anyone else playing with these types of macros.
Brian
whkratz
11-30-2004, 11:05 PM
Nice job Brian!
Amanda, I'm sure that you can see how Brian's "If objRecip.Type = olTo Then ... code answers your question regarding the "To recipients" versus the "CC recipients".
We should still clean up both versions of the macro (disassociating variables, tightening up variable declarations, error handling...), so after both of you (and hopefully some others) play around with it for a bit, report back and then we'll do some housekeeping.
Best Regards.....Bill Kratz
ameasha
12-01-2004, 06:21 AM
When I add in the line
If objRecip.Type = olTo Then
I am getting an error that I have a Next without a For ?? - It seems to be referring to the next at the end of the script.
Am I not adding enough in? Perhaps I should start over?
Thanks guys.
bdavidson
12-01-2004, 06:23 AM
When I add in the line
If objRecip.Type = olTo Then
I am getting an error that I have a Next without a For ?? - It seems to be referring to the next at the end of the script.
Am I not adding enough in? Perhaps I should start over?
Thanks guys.
Don't forget the
End If
before the Next to close out the If statement.
Brian
ameasha
12-01-2004, 06:42 AM
Now I'm getting an error that I have an End If without a Block If :?:
End If
Next
Else:
MsgBox "Oops!!! This macro only works with Mail Items."
Exit Sub
End If
End Sub
Is the end of my script.
bdavidson
12-01-2004, 07:21 AM
Can you post your entire code?
ameasha
12-01-2004, 07:33 AM
Sub AtWaitingForTasksFromEmail()
' Comments :
' Parameters: -
' Modified :
'
' --------------------------------------------------
Dim objTask As Outlook.TaskItem
Dim objApp As Outlook.Application
Dim objCurrentItem As Object
Dim objRecips As Outlook.Recipients
Dim objRecip As Outlook.Recipient
Set objApp = Outlook.CreateObject("Outlook.Application")
Set objCurrentItem = GetCurrentItem()
If objCurrentItem.Class = olMail Then
Set objRecips = objCurrentItem.Recipients
For Each objRecip In objRecips
Set objTask = objApp.CreateItem(olTaskItem)
objTask.Attachments.Add objCurrentItem
objTask.Subject = objRecip & " - " & objCurrentItem.Subject & " " & Format(Now, "mm.dd.yy")
objTask.ReminderSet = False
objTask.ReminderTime = DateAdd("d", 7, Now)
objTask.Categories = "@WaitingFor"
objTask.Display
objTask.Save
End If
Next
Else:
MsgBox "Oops!!! This macro only works with Mail Items."
Exit Sub
End If
End Sub
Function GetCurrentItem() As Object
' Comments :
' Parameters: -
' Returns : Object -
' Modified :
'
' --------------------------------------------------
Dim objApp As Application
Dim objSel As Selection
Dim objCurrentItem As Object
Set objApp = CreateObject("Outlook.Application")
Select Case objApp.ActiveWindow.Class
Case olExplorer
Set objSel = objApp.ActiveExplorer.Selection
If objSel.Count > 0 Then
Set objCurrentItem = objSel.Item(1)
End If
Case olInspector
Set objCurrentItem = objApp.ActiveInspector.CurrentItem
Case Else
End Select
Set GetCurrentItem = objCurrentItem
Set objCurrentItem = Nothing
Set objSel = Nothing
Set objApp = Nothing
End Function
What do you think?
bdavidson
12-01-2004, 07:51 AM
You're missing the
If objRecip.Type = olTo Then
immediately after the For statement.
Try that! :D
ameasha
12-01-2004, 08:02 AM
It worked! Thank you! I must have been putting it in the wrong place before.
Thanks so much for your help.
Michael Hyatt
12-04-2004, 06:59 AM
Can someone re-post the complete, corrected code? I would like to direct my blog readers to this great macro. (Also, Bill has anything new happened on your Web site? I'd be happy to direct people there, too.)
ameasha
12-06-2004, 06:41 AM
Michael, here is the complete working code:
Sub AtWaitingForTasksFromEmail()
' Comments :
' Parameters: -
' Modified :
'
' --------------------------------------------------
Dim objTask As Outlook.TaskItem
Dim objApp As Outlook.Application
Dim objCurrentItem As Object
Dim objRecips As Outlook.Recipients
Dim objRecip As Outlook.Recipient
Set objApp = Outlook.CreateObject("Outlook.Application")
Set objCurrentItem = GetCurrentItem()
If objCurrentItem.Class = olMail Then
Set objRecips = objCurrentItem.Recipients
For Each objRecip In objRecips
If objRecip.Type = olTo Then
Set objTask = objApp.CreateItem(olTaskItem)
objTask.Attachments.Add objCurrentItem
objTask.Subject = objRecip & " - " & objCurrentItem.Subject & " " & Format(Now, "mm.dd.yy")
objTask.ReminderSet = True
objTask.ReminderTime = DateAdd("d", 7, Now)
objTask.Categories = "@WaitingFor"
objTask.Display
objTask.Save
End If
Next
Else:
MsgBox "Oops!!! This macro only works with Mail Items."
Exit Sub
End If
End Sub
Function GetCurrentItem() As Object
' Comments :
' Parameters: -
' Returns : Object -
' Modified :
'
' --------------------------------------------------
Dim objApp As Application
Dim objSel As Selection
Dim objCurrentItem As Object
Set objApp = CreateObject("Outlook.Application")
Select Case objApp.ActiveWindow.Class
Case olExplorer
Set objSel = objApp.ActiveExplorer.Selection
If objSel.Count > 0 Then
Set objCurrentItem = objSel.Item(1)
End If
Case olInspector
Set objCurrentItem = objApp.ActiveInspector.CurrentItem
Case Else
End Select
Set GetCurrentItem = objCurrentItem
Set objCurrentItem = Nothing
Set objSel = Nothing
Set objApp = Nothing
End Function
bdavidson
12-06-2004, 08:35 AM
Can someone re-post the complete, corrected code? I would like to direct my blog readers to this great macro. (Also, Bill has anything new happened on your Web site? I'd be happy to direct people there, too.)
I have also edited my original message (http://www.davidco.com/forum/viewtopic.php?p=11548#11548) to include all the edits I've made to my offshoot of Bill's original code.
ameasha
12-15-2004, 11:45 AM
Dear Bill or any interested Macro Wizard:
I'd love to tweak our macro code to copy the text of the e-mail into the task rather than including the e-mail as an attachment. This would allow me to read the text on my Palm when I'm out and about. Does anyone know what changes I would need to make?
Thank you!!
Amanda
BrianK
12-15-2004, 05:31 PM
Haven't tested this, but try this:
Between
objTask.Categories = "@WaitingFor"
and
objTask.Display
insert:
objTask.Body = objCurrentItem.Body
So it reads:
objTask.Categories = "@WaitingFor"
objTask.Body = objCurrentItem.Body
objTask.Display
That should copy the body of the email (but not the headers) as the body of the task, I think.
And if I've totally botched Bill's code, I apologize.
ameasha
12-16-2004, 06:43 AM
Brian:
Thank you! I'd like to take the attachment off altogether. Do you think removing this line would do the trick?
objTask.Attachments.Add objCurrentItem
Thanks!
Amanda
BrianK
12-16-2004, 07:41 AM
Brian:
Thank you! I'd like to take the attachment off altogether. Do you think removing this line would do the trick?
objTask.Attachments.Add objCurrentItem
Thanks!
Amanda
Oops. :oops:
Yeah, that should do it. Did the objCurrentItem.Body add just the body, and not the headers?
ameasha
12-16-2004, 07:49 AM
Yes, but I hadn't actually noticed that until you pointed it out :oops:
Do you know how we can add the headers too?
Thank you!
Amanda
bdavidson
12-16-2004, 08:44 AM
Yes, but I hadn't actually noticed that until you pointed it out :oops:
Do you know how we can add the headers too?
Thank you!
Amanda
My post here (http://www.davidco.com/forum/viewtopic.php?p=11548#11548) does that in a roundabout manner by creating a forwarded version of the email to put the headers into the body, then copying that body into the task.
Brian
BrianK
12-16-2004, 01:07 PM
Do you know how we can add the headers too?
This is a clunky effort at re-creating the header. Instead of
objTask.Body = objCurrentItem.Body
Try this monster line:
objTask.Body = "From: " & objCurrentItem.SenderName & vbCrLf & "To: " & objCurrentItem.To & vbCrLf & "CC: " & objCurrentItem.CC & vbCrLf & objCurrentItem.SentOn & vbCrLf & "----------" & vbCrLf & vbCrLf & objCurrentItem.Body
It should result in the task body looking like this:
From: Joe Blow
To: Amos Smith, Andy Jones
CC: bettysue @ fakeemail.com
12/15/04 12:19:40 PM
----------
[body of the email]
If you want to play around with other properties that you can add to it, a good list of them is here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaol11/html/olobjMailItem.asp
MsftMan
12-19-2004, 01:12 AM
Can someone re-post the complete, corrected code? I would like to direct my blog readers to this great macro. (Also, Bill has anything new happened on your Web site? I'd be happy to direct people there, too.)
I have also edited my original message (http://www.davidco.com/forum/viewtopic.php?p=11548#11548) to include all the edits I've made to my offshoot of Bill's original code.
Brian, is your code written for an Exchange server or something different? Because I see code that gives my stand alone version some problems. Mainly the difference between the original code:
Dim objRecips As Outlook.Recipients
vs. your code
Dim objRecips As SafeRecipients
Also your code halted on some "objWFMail" commands even though I have Redemption installed.
Thanks,
Steve
bdavidson
12-19-2004, 12:43 PM
Steve,
It was written and tested in an Exchange environment with Outlook 2003, but I'm not keenly aware of any Exchange specific code, unless it's something to do with the way Recipents are handled in a non-Exchange account.
I installed Redemption from www.dimastr.com, even though it also appeared to be installed by the GTD Add-in as well.
Aside from this info, I'm not saavy enough in VBA to isolate the problem any further... :(
Brian
MsftMan
12-19-2004, 01:03 PM
Thanks Brian,
I just didn't know why you had chosen:
Dim objRecips As SafeRecipients over the original Dim objRecips As Outlook.Recipients
Steve
whkratz
12-19-2004, 08:04 PM
Steve -- Exactly what error messages are you getting with the "objWFMail commands"?
Regards.....Bill Kratz
MsftMan
12-20-2004, 08:25 AM
Hi Bill,
Over here in Covington, WA. Happy Holidays neighbor! The code I had used first would just stop running at the first instance of the ObjWFMail code then goes into debug mode with the referenecd line highlighted in yellow. I've since taken it out.
No biggy, the other code is OK... just have to turn the security on each time it's used. Again not a real issue.
Steve
lhuney1034
12-23-2004, 06:52 PM
Hey Bill,
Any suggestion on how to get macros enabled as I continually get message "Macros are not enabled for this application". I'm sure this is a simple fix of which I'm not aware. Thanks for any help.
H
MsftMan
12-23-2004, 07:42 PM
Hey Bill,
Any suggestion on how to get macros enabled as I continually get message "Macros are not enabled for this application". I'm sure this is a simple fix of which I'm not aware. Thanks for any help.
H
Try altering your Security settings. Tools, Macro, Security, then set to Medium. You are probably at high or very high currently.
Steve Banks
Anonymous
12-25-2004, 12:57 PM
This code has prompted an idea that I don't know if it is possible, but would be a total success.
- As email arrives verify if the subject and sender matches an item in the waiting for folder (Subject and To).
- If it does open the received email and the waiting for tast
- Request confirmation from the user to mark the waiting for task as complete.
This would allow a semi-automatic confirmation to delegated tasks.
Any ideas
I would take a stab with VB but I am worthless in that regard (one of my new year resoltuions, though).
Xoff
fionamac
01-22-2005, 03:17 PM
:shock: I'm getting an error
that the script does not exist or invalid when I use the one for combination with a rule.
Any ideas?
Regards, Fiona