Change Category in a Task via macro

Status
Not open for further replies.

llravlin

Member
Outlook version
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
 
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
 
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...
 
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
 
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
.......
 
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.
 
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.
 
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.
 
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.
Similar threads
Thread starter Title Forum Replies Date
M Cannot change category in inbox; Can change it in popup Using Outlook 0
G Change default font size in sticky notes - Outlook Desktop 2021 Using Outlook 2
R Outlook 2021 change view Using Outlook 2
C Change Photo Size of Selected Contacts Outlook VBA and Custom Forms 1
C Mass Change Selected Contact Photos Outlook VBA and Custom Forms 1
M Use Macro to change account settings Outlook VBA and Custom Forms 0
D Unable to change AppointmentItem.Start property Outlook VBA and Custom Forms 3
sjmo2 Change subject for new e-mails only. Outlook VBA and Custom Forms 2
Horsepower Contact phone numbers randomly change Using Outlook 0
P Outlook 2016 Change Paste Special Default Format Using Outlook 8
whizzard Change FROM address based on TO or CC address Outlook VBA and Custom Forms 8
S Outlook 365 Can I change the possible range of highlighting colours when writing an Outlook email? Using Outlook 1
V Can one change the formatting of email title blocks? Using Outlook 0
S Unable to change Message Class Outlook VBA and Custom Forms 0
S New Outlook Appointment - Select All Body Text and Change Font and Size Outlook VBA and Custom Forms 1
J VBA Cannot programmatically input or change Value for User Defined field Using Outlook 1
C Outlook 365 Can you change the follow up colour? Using Outlook 1
A Change settings Send/receive VBA Outlook VBA and Custom Forms 0
E Outlook VBA change GetDefaultFolder dynamically Outlook VBA and Custom Forms 6
O What would be the recommended way to change an email address (family member)? Using Outlook 0
S Change "This Week" flag start date behavior Using Outlook 1
N Help creating a VBA macro with conditional formatting to change the font color of all external emails to red Outlook VBA and Custom Forms 5
D Change Microsoft Account password - what to do to update on all devices Using Outlook 4
S Outlook 2016 Change how Outlook shows me contacts in emails Using Outlook 0
Witzker HowTo Change message Class of contact form Outlook VBA and Custom Forms 0
Z Outlook 365 delete reminder you can’t make change to contents of this-read only folder Using Outlook 4
Witzker Pls help to change the code for inserting date in Ol contact body Outlook VBA and Custom Forms 5
R How to Change Margins In Google Docs...? Using Outlook 0
e_a_g_l_e_p_i Outlook 2010 How can I change the font size on right side appointment pane Using Outlook 12
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
B Change Font and Font size using VBA Outlook VBA and Custom Forms 9
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 10
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
Z 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 90
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

Similar threads

Back
Top