Use this code to remove all categories and set the category to "Completed" when a Task is marked Complete.
You need to use two (or more) If statements with this code. If you check just for Complete = True, it will run forever. In this code sample, I'm checking the Category for "Completed" (and skipping Recurring tasks). If the category is not marked Completed, the code removes all categories and sets the Category to Completed. It saves and then opens the task.
This macro needs to go into ThisOutlookSession. To test the macro, click in Initialize_handler then click the Run button.
See How to use the VBA Editor if you don't know how to use macros.
Public WithEvents OlItems As Outlook.Items Public Sub Initialize_handler() Set OlItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks).Items End Sub Private Sub OlItems_ItemChange(ByVal Item As Object) If Item.Complete = True And Item.IsRecurring = False Then If InStr(1, Item.Categories, "Completed") = False Then With Item .Categories = "" .Categories = "Completed" .Save .Display End With End If End If End Sub
More Information
Create a Task when a message is flagged
Task: Categorize a completed task. (Michael Bauer, VBOffice.net)
This works great - thank you!! Is there any way to also change the category of the CALENDAR entry if the task is dragged onto the calendar? The end goal here is if the task is completed, and if the task exists on the calendar, the calendar shows a completed category, along with the task..
Yes, you could. You'd need to use Find or Restrict to location the matching calendar entry. I don't have a sample handy (and have been meaning to work on one before answering but have been swamped.)
Hi Diane,
For some reason I cannot get custom events to trigger. I did check all of the security settings. I deleted .OTM file and created a new one. I restarted of course multiple times. It still doesn't work.
Do you have any suggestions on what I can check next ?
Did you put the code in thisoutlooksession? Is macro security set to low? Try adding msgbox "Macro working" as the first line of the change macro.
Thank you for your response Diane.
I have no idea where to start. I will need to use code to achieve my desired result, so it looks like I will have to employ someone to do that for me or learn how to do it myself.
It's actually not hard to do, you just need to add the code to create a new task. Follow up here:
Thread at OutlookForums
Is there a way that Outlook can automatically create a new task when a current task is marked complete?
it won't create an entirely new task, but if you use recurring tasks and the option to regenerate tasks, you'll make a new one. Of course, that will be a task identical to the previous task. If you want a different task, you'll need to use code to create it.
Hi Diane,
I have created the code below which creates an email once the Outlook task stored in the sub-folder Completed is marked as completed. Everything works great except the vba generates 3 emails instead of one. Would you be able to point me to the correct solution?
Thank You
Public WithEvents Items As Outlook.Items
Public Sub Initialize_handler()
Set Items = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks).Folders("Completed").Items
End Sub
Private Sub Items_ItemChange(ByVal Item As Object)
Dim objMsg As Outlook.MailItem
Set objMsg = Outlook.Application.CreateItem(olMailItem)
If Item.Status = olTaskComplete And Item.IsRecurring = False Then
If Item.PercentComplete = 100 Then
'create a new message
With objMsg
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = "" _
& "" _
& "Start date: " & Item.StartDate & "" _
& "Due date: " & Item.DueDate
.To = "XXX@XXX.COM"
.CC = "XXX@XXX.COM"
.Subject = "Task Completed: " & Item.Subject
.Display
.Save
End With
End If
End If
Set objMsg = Nothing
End Sub