none
Get Task items as you see them RRS feed

  • Question

  • Hi

    I want to be able to get the Task items in the order as I see them. If I create Task1, task2 and Task3 and use the follwing VBA i get the task in the order I created them.

    Sub GetTask()
        Dim ns As NameSpace
        Dim fld As Folder
        Dim task As TaskItem
        Dim items As Outlook.items
        Dim rest As Outlook.items
       
        Set ns = Application.GetNamespace("MAPI")
        Set fld = ns.PickFolder()
        Set items = fld.items
        Set rest = items.Restrict("[Status] <> 'Completed'")
       
        For Each task In rest
            MsgBox (task.Subject & " | " & task.Role)
            task.Role = "1"
            task.Save
        Next
       
    End Sub

    But if I drag the task so they are in the following order Task3, Task1 and Task2. How should I write the code so I get them in the order as they are displayed in Outlook after I have draged my tasks around, in this case 3, 1, 2?

    I want to get the Task in the order as I have prioritized them.

    Regards
    Niklas


    Regards Niklas

    Tuesday, February 12, 2013 3:02 PM

Answers

  • Your code can only do what the Outlook object model allows it to do. Diane's tip only applies to how tasks are shown in a view in the user interface. It has nothing to do with what you can or cannot do in code.

    You can sort by Importance to get a sorted prioritized Items collection, but that's about it.


    Ken Slovak MVP - Outlook

    Wednesday, February 13, 2013 4:17 PM
    Moderator
  • This has nothing to do with VBA or C# or VSTO or phases of the moon. The Outlook object model doesn't let you do what you want, no matter what language or development platform you're using.

    You can't do what you want how you want to do it. You will need to re-design what you're doing.


    Ken Slovak MVP - Outlook

    Friday, February 15, 2013 4:08 PM
    Moderator

All replies

  • The Tasks (or any Items collection) will be returned usually in the order the items were created unless you apply a sort to the collection.

    What is the sort order of items you see in your view of the items? You would need to sort on the same field.


    Ken Slovak MVP - Outlook

    Tuesday, February 12, 2013 4:16 PM
    Moderator
  • Hi

    I'm not using a traditionally sort, I'm dragging the task to the position I want according to the priority of importance. In other words I create a prioritized list and I want to loop thru my prioritized list.

    Dragging task, see this article:
    http://www.outlook-tips.net/tips/tip-997-drag-reorder-todo-list/

    Regards
    Niklas


    Regards Niklas

    Wednesday, February 13, 2013 6:03 AM
  • Your code can only do what the Outlook object model allows it to do. Diane's tip only applies to how tasks are shown in a view in the user interface. It has nothing to do with what you can or cannot do in code.

    You can sort by Importance to get a sorted prioritized Items collection, but that's about it.


    Ken Slovak MVP - Outlook

    Wednesday, February 13, 2013 4:17 PM
    Moderator
  • OK, so the VBA Outlook Information model don't allow looping thru the collection of Task which represent the view in the user interface. Can I do it using VSTO and C# or even C?

    My main goal is to create a prioritized list and I want to be able to save the order of this list so I can use it later. My solution was to loop thru the prioritized list and use the “role” field to populate it with number 1 (highest priority) to n (lowest priority). Any other solutions how I can drag tasks around and save the final list in an easy way? (Importance and Priority have to few records to be really useful).


    Regards Niklas

    Thursday, February 14, 2013 7:52 AM
  • This has nothing to do with VBA or C# or VSTO or phases of the moon. The Outlook object model doesn't let you do what you want, no matter what language or development platform you're using.

    You can't do what you want how you want to do it. You will need to re-design what you're doing.


    Ken Slovak MVP - Outlook

    Friday, February 15, 2013 4:08 PM
    Moderator