Welcome to TechNet Blogs Sign in | Join | Help

KC Lemson

By KC Lemson [MS]

News

  • These postings are provided "AS IS" with no warranties, and confer no rights.

    Please read my comments policy.


Create a task from an email

John Durant recently blogged about his macro to create a task from an e-mail. I thought that was a great idea, so I modified it a bit to suit my purposes. I frequently take an item from my inbox and Edit | Move to Folder and move it to the tasks folder, which creates a task item. I then tab around to set the reminder (which is frustrating if I want it to remind me later today, because if I put 'today' in the due date, it doesn't set the reminder, thus resulting in more keystrokes).

This macro does the following:

1. Takes the items that are selected (it can handle multiple selections of any item type)
2. Creates a task
3. Attaches those items
4. Deletes the items from the source folder
5. Saves the task (so worst case, you can go get the items from the task if you didn't want them to be removed)
6. Sets the reminder on the task to 3 hours from now (you can easily tab into the due date field and set it to tomorrow, tuesday, etc, which will in turn change the reminder)

So, here's what I did:

1. Copy the code into ThisOutlookSession per the instructions in this entry
2. Add a toolbar button for this macro per the instructions in this entry (Note: K as an accelerator isn't used by default in the standard toolbars, so Create Tas&k is a good name - you can also change the icon to something else in that menu as well)

And finally, the code:

Public Sub CreateTaskFromItem()

  Dim olTask As Outlook.TaskItem
  'Using object rather than MailItem, so that it
  'can handle posts, meeting requests, etc as well

  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 olTask = olApp.CreateItem(olTaskItem)
  Set olExp = olApp.ActiveExplorer
  Set fldCurrent = olExp.CurrentFolder
 
  Dim cntSelection As Integer
  cntSelection = olExp.Selection.Count
 
  For i = 1 To cntSelection
    Set olItem = olExp.Selection.Item(i)
    olTask.Attachments.Add olItem
    olTask.Subject = "Follow up on " & olItem.Subject
    olItem.Delete
  Next

  olTask.Display
  'Set the due date for today
  olTask.DueDate = Date
  'Set the reminder for 3 hours from now
  olTask.ReminderSet = True
  olTask.ReminderTime = DateAdd("h", 3, Now)
 
  'Saving the task item, so that in case I close it, I won't lose
  'the items which were deleted after being attached to the task

  olTask.Save
 
End Sub

Posted: Saturday, January 31, 2004 12:26 PM by kclemson

Comments

Colin Walker said:

This works a treat. I saw the original but I like what you've done with it.

This is now on my toolbar :o)
# January 31, 2004 1:23 PM

Colin Walker said:

Although, I must admit I removed "olItem.Delete" as I prefer to keep the original mails ;o)
# January 31, 2004 1:57 PM

CTL-F5 said:

# January 31, 2004 5:27 PM

KC on Exchange and Outlook said:

# February 2, 2004 7:52 PM

Steve Downs said:

I have to ask, what is wrong with drag and drop?

Drag e-mail to tasks, task opens click the reminder check box, click (and hold) on the down arrow for the time and keep holding the button down below the bottom of the dropdown time list list untill it scrolls to the time you want, slide mouse to highlight let go and click save and close. Push your delete key to delete the e-mail. That takes less that 3 seconds.

I supose if you really want the cool macro button that's ok but drag and drop is easy too.

By the way the junk mail filter on Outlook 2003 Rocks. The team that came up with it ought to get a big promotion. I spent about 4-5 days using Outlook and marking what I didn't want. I seldom receive an junk e-mail now. Good Job

Oh and while I'm at it hiding the graphics in the messages untill you want to show them is an awesome feature too.
# February 4, 2004 6:35 PM

KC on Exchange and Outlook said:

# February 12, 2004 4:56 PM

Peter Duckett said:

I like what you have done with the code very smart!! but will it add file attacements as well as the email to the task as well as i have been havin problems doing this!! thanks peter
# June 29, 2004 2:21 AM

Peter Duckett said:

What i meant to say is how can i just copy the email inot a task in the same format without putting it into an attachments
# June 30, 2004 6:29 AM

KC Lemson said:

Peter: I haven't tried it out, but I suspect something like this would work:

Replace this:

olTask.Attachments.Add olItem

With:

olTask.body = oltask.body & vbcrlf & olitem.body
# June 30, 2004 7:48 AM

Peter Duckett said:

Thank you for you last comment that worked fine i was able to copy the emails body into an task easy enough using that but i would i would like to copy the attachments over too in the same position that it was placed.
I had tryied this code which copys the attacment and then adds it to the task supposed to be in the same position but it seems it comes out completly random placement left or right to where its supposed to be

OlOrig.Attachments.Item(i).SaveAsFile "C:\" & OlOrig.Attachments.Item(i).DisplayName
objattachments.Add "C:\" & OlOrig.Attachments.Item(i).DisplayName, , OlOrig.Attachments.Item(i).position
Kill ("C:\" & OlOrig.Attachments.Item(i).DisplayName)

If you could help just to copy over these attachments in the correct place i would be very happy thank you
# July 1, 2004 3:02 AM

KC Lemson said:

I don't have any expertise in what determines the insertion point of the attachment, sorry.
# July 2, 2004 4:01 PM

Narayanan Sankaranarayanan said:

Hi,

I am Narayanan Sankararanarayanan.

We have a web-based application that has reminders for users.
These reminders popup as long as they are in the web-based application. We have Outlook as our corporate email client.
We want these reminders to be part of outlook/exchange.

Here is my question: How will you create a task for somebody? It should look like that person by him/herself has created the task.

Thanks

Narayanan Sankararanarayanan
# July 20, 2004 7:54 AM

Thom Allen said:

# November 5, 2004 11:50 AM

Thom Allen said:

# November 5, 2004 11:51 AM
New Comments to this post are disabled
Page view tracker