Change Category in a Task via macro

Status
Not open for further replies.

llravlin

Member
Outlook version
Outlook 2007
Email Account
I am trying to change a task category using a macro by opening the categories dialog box while in the task and have it automatically change the name and mark it complete..

I've started some code, but I can't get anything to work. Any help is appreciated

Public Sub TagCompleted()
Dim objOutlook As Outlook.Application
Dim objInspector As Outlook.Inspector
Dim strDateTime As String
' Instantiate an Outlook Application object.
Set objOutlook = CreateObject("Outlook.Application")
' The ActiveInspector is the currently open item.
Set objExplorer = objOutlook.ActiveExplorer
' Check and see if anything is open.
If Not objExplorer Is Nothing Then ' Get the current item.
Dim arySelection As Object
Set arySelection = objExplorer.Selection
For x = 1 To arySelection.Count
strCats = arySelection.Item(x).ShowCategoriesDialogue
If Not strCats = "" Then
strCats = strCats & ","
End If
strCats = strCats
arySelection.Item(x).Categories = strCats
arySelection.Item(x).Completed
arySelection.Item(x).Save
Next x
Else ' Show error message with only the OK button.
MsgBox "No explorer is open", vbOKOnly
End If ' Set all objects equal to Nothing to destroy them and
' release the memory and resources they take.
Set objOutlook = Nothing
Set objExplorer = Nothing
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
So you just want to change a task from Blue Category to Red Category and mark it complete? Or do you want to select the specific category?

I have this macro - http://www.slipstick.com/developer/code-samples/change-category-task-marked-completed/ which is automatic. When you mark it complete, it changes the category.

to mark complete, try this format:
.complete = true

if you want the category picker, use this format - US English. :)
.ShowCategoriesDialog

do you want to keep the old category and add a new one or remove old categories so it has only the new one?

i usually use for each item in selection rather than counting them, then set objitem = the current item.

Code:
Sub UseSelection() 
    Dim currentExplorer As Explorer 
    Dim Selection As Selection 
    Dim obj As Object
   Set currentExplorer = Application.ActiveExplorer 
    Set Selection = currentExplorer.Selection
   On Error Resume Next
   For Each obj In Selection
           Set objItem = obj
           With objItem 
' do whatever 
                .Save 
            End With 
        Err.Clear 
    Next
   Set Session = Nothing 
    Set currentExplorer = Nothing 
    Set obj = Nothing 
    Set Selection = Nothing 
 
End Sub
 

llravlin

Member
Outlook version
Outlook 2007
Email Account
So you just want to change a task from Blue Category to Red Category and mark it complete? Or do you want to select the specific category?

I have this macro - http://www.slipstick.com/developer/code-samples/change-category-task-marked-completed/ which is automatic. When you mark it complete, it changes the category.

to mark complete, try this format:
.complete = true

if you want the category picker, use this format - US English. :)
.ShowCategoriesDialog

do you want to keep the old category and add a new one or remove old categories so it has only the new one?

i usually use for each item in selection rather than counting them, then set objitem = the current item.

Code:
Sub UseSelection() 
    Dim currentExplorer As Explorer 
    Dim Selection As Selection 
    Dim obj As Object
   Set currentExplorer = Application.ActiveExplorer 
    Set Selection = currentExplorer.Selection
   On Error Resume Next
   For Each obj In Selection
           Set objItem = obj
           With objItem 
' do whatever 
                .Save 
            End With 
        Err.Clear 
    Next
   Set Session = Nothing 
    Set currentExplorer = Nothing 
    Set obj = Nothing 
    Set Selection = Nothing 
 
End Sub
I want to be able to pick the category and change to complete. I want to do it using a macro so not in ThisOutlookSession (I have other code there).

I want to replace the category so it only has the new one.

I already am using the ShowCategoriesDialogue which pops up, but doesn't change it/save it after I select my new category and hit OK. And I can't get it to change to complete...
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I had an appointment this morning and wasn't able to test your macro

The reason the category doesn't save is because you are using it wrong- you don't assign it to a viariable, you just need to call it up -
arySelection.Item(x).ShowCategoriesDialog

This version works on an open or selected message. If you are using tasks, not flagged messages, you need to use
arySelection.Item(x).Status = olTaskComplete

Code:
Public Sub TagCompleted() 
Dim objOutlook As Outlook.Application 
Dim objInspector As Outlook.Inspector 
Dim strDateTime As String 
' Instantiate an Outlook Application object. 
Set objOutlook = CreateObject("Outlook.Application") 
' The ActiveInspector is the currently open item. 
Set objExplorer = objOutlook.ActiveExplorer 
' Check and see if anything is open. 
If Not objExplorer Is Nothing Then ' Get the current item. 
Dim arySelection As Object 
Set arySelection = objExplorer.Selection 
 
For x = 1 To arySelection.Count 
arySelection.Item(x).ShowCategoriesDialog 
 
' if working with messages 
arySelection.Item(x).FlagStatus = olFlagComplete 
 
' for tasks use this instead 
'arySelection.Item(x).Status = olTaskComplete 
 
arySelection.Item(x).Save 
Next x 
 
Else ' Show error message with only the OK button. 
MsgBox "No explorer is open", vbOKOnly 
End If ' Set all objects equal to Nothing to destroy them and 
' release the memory and resources they take. 
Set objOutlook = Nothing 
Set objExplorer = Nothing 
End Sub
 

llravlin

Member
Outlook version
Outlook 2007
Email Account
I receive an error "object doesn't support this property or method" with the code:

arySelection.Item(x).ShowCategoriesDialogue
......
If Not objExplorer Is Nothing Then ' Get the current item.
Dim arySelection As Object
Set arySelection = objExplorer.Selection
For x = 1 To arySelection.Count
arySelection.Item(x).ShowCategoriesDialogue
arySelection.Item(x).Categories = strCats
arySelection.Item(x).Status = olTaskComplete
arySelection.Item(x).Save
Next x
.......
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
use arySelection.Item(x).ShowCategoriesDialog - that should not error, at least not on that line. You don't need this line: arySelection.Item(x).Categories = strCats as the categories are added as soon as you select them.
 

llravlin

Member
Outlook version
Outlook 2007
Email Account
It just doesn't want to work :-( It will not change the category or change it to complete. I'm at a loss...The categories box comes up, I change it, but it doesn't change the category.
 

larry

Senior Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
The last macro D posted, #4 works here in Outlook 2007.

To use it with Tasks, remove these lines:
' if working with messages
arySelection.Item(x).FlagStatus = olFlagComplete

and remove the ' from this one.
' for tasks use this instead
'arySelection.Item(x).Status = olTaskComplete

When I first tested it in tasks, it errored because I selected a flagged message in the To-Do list, then it looked like it wasn't working because I used a view that hid completed tasks. I discovered the error in my ways when I tested it on an open task. Oops.
 

llravlin

Member
Outlook version
Outlook 2007
Email Account
My problem isn't with the "complete" it is with the categories. I have a category already assigned to the task. I want to change that category and mark complete with a macro. With the task opened, I run the macro, when the categories dialog box opens there is no category chosen; which I think it would since the task does have a category already. With the box opened I choose a category and it does not change the category. Marking complete is fine...
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
M Cannot change category in inbox; Can change it in popup Using Outlook 0
M 2007 Outlook Calendar - Inability to change one appointment label/category in a series Using Outlook 1
D Change senders title Using Outlook 1
W Recurrence: delete older occurrences / change earliest start time Outlook VBA and Custom Forms 0
E Change sending account depending on Subjectline Outlook VBA and Custom Forms 0
J Outlook 2013 Change color of text in data fields of contacts in Outlook 2013? Using Outlook 3
B Change row background color of selected item Using Outlook 1
PGSystemTester VBA To Change AppointmentItem.BusyStatus From MeetingItem Before Send Using Outlook 0
B Change from Address Outlook VBA and Custom Forms 0
X If you change expiration date of repeated task it dupplicates Using Outlook 1
E How to display "Change Folder" in Change Default Email Delivery Location in Exchange Outlook 2016 Using Outlook 1
B See "Change View" Drop Down as a List? Using Outlook 1
V Change start time based on message duration Outlook VBA and Custom Forms 2
R Folder pane width change Using Outlook 52
S Change VBA script to send HTML email instead of text Outlook VBA and Custom Forms 3
S Outlook 2010 unable to change default font Using Outlook 7
P How can I change my calendar view back Using Outlook 3
A Edit subject - and change conversationTopic - using VBA and redemption Outlook VBA and Custom Forms 2
T Change the selected Message in the Outlook window Outlook VBA and Custom Forms 2
geofferyh How to change the Attachment File Name? Outlook VBA and Custom Forms 1
W Appointment occurrences change the location property Using Outlook 0
T Scheduled footer change Using Outlook 2
B Change font of reminder of an email header Outlook VBA and Custom Forms 3
CWM030 Name Change? Exchange Server Administration 9
V not able to change name in customize Ribbon Outlook VBA and Custom Forms 1
JoeG Appointment Delete/Change Recurrence Outlook VBA and Custom Forms 0
C Change Subject Line in Selected Emails Outlook VBA and Custom Forms 1
V Change default default save location to Quick Access Using Outlook 1
C Change default "Save Sent Item To" folder Outlook VBA and Custom Forms 9
S Example VBA Macro - To Conditionally Change the From Account and Add a BCC Address on Emails Outlook VBA and Custom Forms 11
B Do not change the From address in Outlook Templates Using Outlook 0
M Sudden change in From field - now very short Using Outlook 4
M cannot change delivery folders with IMAP accounts Using Outlook 0
S Email Format With Embedded Images and Tables Change Using Outlook 2
O On click,I want to change subject line of selected mail and then reply to particular email and move Using Outlook 3
P Change PC User Directory & iPhone Sync Using Outlook 2
A Change order of actions in one (!) rule Outlook VBA and Custom Forms 2
I change subject and forward without FW: Outlook VBA and Custom Forms 4
Rupert Dragwater Can't change font size Using Outlook 5
M VBA to change flag status in outlook contact item Outlook VBA and Custom Forms 3
J Auto Forward - Include Attachment and change Subject depending on original sender Outlook VBA and Custom Forms 3
tjd189 outlook 2016 name change Using Outlook 1
E Button to change subject Outlook VBA and Custom Forms 1
K Paste from Windows Clipboard then change font without losing formatting Outlook VBA and Custom Forms 1
D Office365 Conference Room name change? Using Outlook 5
J Change POP account to Forwarder - What happens in Outlook? Using Outlook 2
H Change Default Email Account Using VBA Outlook VBA and Custom Forms 5
C Change default colors for conditional formatting Using Outlook 2
O VBA to Run Font Change on Outlook Startup Outlook VBA and Custom Forms 4
K Other Shared Calendar on Outlook cannot change items Using Outlook.com accounts in Outlook 7
Similar threads


















































Top