none
Outlook "To-Do List" folder. Get items for all accounts RRS feed

  • Question

  • Hi everyone,

    I have two mail accounts in my Outlook and therefore there are two task folders. There are task items in each folder, each mail account has mail items which I marked by Follow-Up flag. To-Do List folder combine all my tasks and follow-up mails into single table view and it's very convenient. 

    However, there is a problem with To-Do list and access to all its items via VBA script or C# code (VSTO). 

        Dim f1 As Folder
        Set f1 = Outlook.GetNamespace("MAPI").GetDefaultFolder(olFolderToDo)
        MsgBox (f1.Items.Count)

    In Outlook window I see 4 tasks (two of them are in the first mail account, another two are in the second one), but when I call the code above I get "2" in the message box window. The folder object in VBA script knows only about items from the default account. Is there any possibility to get all task items from all accounts via VBA (or C#) like I see in Outlook window in To-Do List view?

    I think, I can enumerate through the all accounts, get Task folder for each of them and recursively move through the folder structure to get all task items, but it's not so convenient as work with Items object in the plane To-Do List folder, and of course this will take more time to update my task list.

    Any help will be very much appreciated.

    Thanks, Mikahil

    Friday, March 1, 2013 11:40 AM

Answers

  • Not all items that will be in the ToDo bar will be in the respective Store's Tasks folder. Flag an email and see what I mean. Doing that adds various Task properties to an item that allow it to be found by the ToDo Search folder.
     
    Code like this VBA can be used to iterate each ToDo folder in each loaded Store:
     
    Sub testToDo()
        Dim f1 As Folder
        Dim oStore As Outlook.Store
        For Each oStore In Application.Session.Stores
            Debug.Print oStore.DisplayName
            Set f1 = oStore.GetDefaultFolder(olFolderToDo)
            Debug.Print (f1.Items.Count)
            Dim obj As Object
            Dim oTask As Outlook.TaskItem
            Dim n As Long
            n = 1
           
            For Each obj In f1.Items
                Debug.Print n, obj.Parent.Store.DisplayName
                n = n + 1
            Next
        Next
    End Sub
     
    A possible alternative might be even faster using Folder.GetTable() to get a table of each folder's items.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "mbelov1" <=?utf-8?B?bWJlbG92MQ==?=> wrote in message news:90fa2661-fe53-4e90-a04d-445478c287b2...

    Hi everyone,

    I have two mail accounts in my Outlook and therefore there are two task folders. There are task items in each folder, each mail account has mail items which I marked by Follow-Up flag. To-Do List folder combine all my tasks and follow-up mails into single table view and it's very convenient. 

    However, there is a problem with To-Do list and access to all its items via VBA script or C# code (VSTO). 

        Dim f1 As Folder
        Set f1 = Outlook.GetNamespace("MAPI").GetDefaultFolder(olFolderToDo)
        MsgBox (f1.Items.Count)

    In Outlook window I see 4 tasks (two of them are in the first mail account, another two are in the second one), but when I call the code above I get "2" in the message box window. The folder object in VBA script knows only about items from the default account. Is there any possibility to get all task items from all accounts via VBA (or C#) like I see in Outlook window in To-Do List view?

    I think, I can enumerate through the all accounts, get Task folder for each of them and recursively move through the folder structure to get all task items, but it's not so convenient as work with Items object in the plane To-Do List folder, and of course this will take more time to update my task list.

    Any help will be very much appreciated.

    Thanks, Mikahil


    Ken Slovak MVP - Outlook
    • Marked as answer by mbelov1 Monday, March 4, 2013 6:28 PM
    Friday, March 1, 2013 6:43 PM
    Moderator

All replies

  • i;m afraid you will have to - search folders are scoped to store and most probably this is what this task pane does underneath anyway.
    Friday, March 1, 2013 12:19 PM
  • Not all items that will be in the ToDo bar will be in the respective Store's Tasks folder. Flag an email and see what I mean. Doing that adds various Task properties to an item that allow it to be found by the ToDo Search folder.
     
    Code like this VBA can be used to iterate each ToDo folder in each loaded Store:
     
    Sub testToDo()
        Dim f1 As Folder
        Dim oStore As Outlook.Store
        For Each oStore In Application.Session.Stores
            Debug.Print oStore.DisplayName
            Set f1 = oStore.GetDefaultFolder(olFolderToDo)
            Debug.Print (f1.Items.Count)
            Dim obj As Object
            Dim oTask As Outlook.TaskItem
            Dim n As Long
            n = 1
           
            For Each obj In f1.Items
                Debug.Print n, obj.Parent.Store.DisplayName
                n = n + 1
            Next
        Next
    End Sub
     
    A possible alternative might be even faster using Folder.GetTable() to get a table of each folder's items.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "mbelov1" <=?utf-8?B?bWJlbG92MQ==?=> wrote in message news:90fa2661-fe53-4e90-a04d-445478c287b2...

    Hi everyone,

    I have two mail accounts in my Outlook and therefore there are two task folders. There are task items in each folder, each mail account has mail items which I marked by Follow-Up flag. To-Do List folder combine all my tasks and follow-up mails into single table view and it's very convenient. 

    However, there is a problem with To-Do list and access to all its items via VBA script or C# code (VSTO). 

        Dim f1 As Folder
        Set f1 = Outlook.GetNamespace("MAPI").GetDefaultFolder(olFolderToDo)
        MsgBox (f1.Items.Count)

    In Outlook window I see 4 tasks (two of them are in the first mail account, another two are in the second one), but when I call the code above I get "2" in the message box window. The folder object in VBA script knows only about items from the default account. Is there any possibility to get all task items from all accounts via VBA (or C#) like I see in Outlook window in To-Do List view?

    I think, I can enumerate through the all accounts, get Task folder for each of them and recursively move through the folder structure to get all task items, but it's not so convenient as work with Items object in the plane To-Do List folder, and of course this will take more time to update my task list.

    Any help will be very much appreciated.

    Thanks, Mikahil


    Ken Slovak MVP - Outlook
    • Marked as answer by mbelov1 Monday, March 4, 2013 6:28 PM
    Friday, March 1, 2013 6:43 PM
    Moderator
  • Hi Ken,

    Thanks a lot. I can get all task iterating through the all stores and receiving task folder from each one. However, I was not able to find GetDefaultFolder method in the Store type. Instead of this I used the following method:

    Set f1 = oStore.GetSpecialFolder(olSpecialFolderAllTasks)

    Thanks,

    Mikhail

    Monday, March 4, 2013 11:47 AM
  • That Store method would also work, but at least for Outlook 2010 and later there definitely is a Store.GetDefaultFolder() method, I'm staring at it now in the Outlook VBA project Object Browser.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "mbelov1" <=?utf-8?B?bWJlbG92MQ==?=> wrote in message news:42f1d28d-0cb2-4d16-8236-f6f00014d439...

    Hi Ken,

    Thanks a lot. I can get all task iterating through the all stores and receiving task folder from each one. However, I was not able to find GetDefaultFolder method in the Store type. Instead of this I used the following method:

    Set f1 = oStore.GetSpecialFolder(olSpecialFolderAllTasks)

    Thanks,

    Mikhail


    Ken Slovak MVP - Outlook
    Monday, March 4, 2013 6:15 PM
    Moderator
  • I think that's the reason: I'm using Outlook 2007 for my tests. It's because I need to support Outlook 2007 - 2013.

    Anyway, thanks again for your help.

    Mikhail.


    Monday, March 4, 2013 6:31 PM
  • Ah, 2007 support. Yes, in that case GetSpecialFolder() would be what you'd want to use.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "mbelov1" <=?utf-8?B?bWJlbG92MQ==?=> wrote in message news:8d69fc97-4652-43e1-a26b-1f649b5d3165...

    I think that's the reason: I'm using Outlook 2007 for my tests. It's because I need to support Outlook 2007 - 2013.

    Anyway, thanks again for your help.

    Mikhail.



    Ken Slovak MVP - Outlook
    Monday, March 4, 2013 6:41 PM
    Moderator