none
[Solved] Tasks subfolder? RRS feed

  • Question

  • I found this macro and it works just great for opening my default tasks folder:

    Sub TASKS_open_in_new_window()
        Dim oFolder As Outlook.Folder
            Set oFolder = Application.Session.GetDefaultFolder(olFolderTasks)
        oFolder.Display
    End Sub
    

    From here, I found this syntax, hoping that I could adjust it for a task subfolder: 

    Session.GetDefaultFolder(olFolderInbox).Folders("subfolder name")
    

    which I modified to this:

    Set oFolder = Application.Session.GetDefaultFolder(olFolderTasks).Folders("TASKS (Folder Paths)")
    

    So just need to adjust so that my custom TASK folder is opened, labelled:  TASKS (Folder Paths).

    Thank you!


    • Edited by SGFan Friday, November 13, 2015 9:24 PM
    Thursday, November 12, 2015 10:11 PM

Answers

  • If you custom folder is on the same level as your default Tasks folder (and the Inbox), all you need to do is go one level up to the root folder and then retrieve the subfolder:

    Set oFolder = Application.Session.GetDefaultFolder(olFolderTasks).Parent.Folders('Your Folder Name')


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Friday, November 13, 2015 8:56 PM

All replies

  • Looks perfectly fine. What is the problem?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, November 12, 2015 10:17 PM
  • Hi!

    Sure, the syntax for opening my default tasks folder works fine but not my custom one labelled:

    "TASKS (Folder Paths)"

    When I run this modified script (though, granted, not sure it would work, to begin with):

    Sub TASKS_open_in_new_window()
        Dim oFolder As Outlook.Folder
            Set oFolder = Application.Session.GetDefaultFolder(olFolderTasks).Folders("TASKS (Folder Paths)")
        oFolder.Display
    End Sub

    I get this error code:

    Run-time error '-2147221233 (8004010f)':
    
    The attempted operation failed.  An object could not be found.

    Thank you!


    • Edited by SGFan Friday, November 13, 2015 1:42 AM
    Friday, November 13, 2015 1:42 AM
  • Hi SGFan,

    The code seems to be fine. Please ensure the folder you want to retrieve is an subfolder of task.

    As far as I know, when we create a folder under "My Tasks" group, the new folder is nota subfolder of task. It would be created under Inbox.

    We can the folder path via right click the folder property like figure below:

    And we can add subfolder for the task via switch folders and right click the folder to add a new folder like figure below:

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 13, 2015 5:15 AM
    Moderator
  • Hello SGFan,

    Try to iterate over all Folders checking subfolder names. See How to: Enumerate Folders for more information.

        Outlook.Folders childFolders =
            folder.Folders;
        if (childFolders.Count > 0)
        {
            foreach (Outlook.Folder childFolder in childFolders)
            {
                // Write the folder path.
                Debug.WriteLine(childFolder.FolderPath);
                // Call EnumerateFolders using childFolder.
                // EnumerateFolders(childFolder);
            }
        }

    Do you see the required folder there?

    If so, you may check the Name property of the Folder class in the for loop.

    Friday, November 13, 2015 10:34 AM
  • Hi SGFan,

    The code seems to be fine. Please ensure the folder you want to retrieve is an subfolder of task.

    As far as I know, when we create a folder under "My Tasks" group, the new folder is nota subfolder of task. It would be created under Inbox.

    We can the folder path via right click the folder property like figure below:

    [snip]

    Fei, hello and thank you!!

    That's it!  That's the problem.  I don't know how I missed something so obvious!  My custom tasks folder is not a subfolder of Tasks but is an actual folder by itself.

    Also, I did look for the path in the properties before this but I don't get what you do, an actual location, which is why I gave up on that - and I can't install the linker add-in that I found reference to online and dl, just for this purpose.  We're on Windows 7 now and it requires administrator rights so couldn't use that to be able to easily find real paths to folders in Outlook.

    The location in the properties of my custom task folder shows this:

    \\my email address

    that's it.

    So I tried a couple of things like this today: 

    Sub TASKS_open_in_new_window()
        Dim oFolder As Outlook.Folder
    '        Set oFolder = Application.Session.GetDefaultFolder(olFolderTasks) ' this line for opening the default Tasks folder in your profile.
            Set oFolder = Application.Session.GetDefaultFolder(olFolderTasks).Folders(\\(my email address)\Inbox\TASKS (Folder Paths))  ' this line for opening your custom Tasks folder.
        oFolder.Display
    End Sub

    I tried with and without the Inbox portion in the line but I suspect it's because it's not a subfolder of Tasks and perhaps some other means of calling is needed?

    But at least I'm one step closer ...






    • Edited by SGFan Friday, November 13, 2015 3:50 PM
    Friday, November 13, 2015 3:47 PM
  • Yikes, Eugene!  I'll put this on the back burner till later today.  I'm a dunce when something is really different from the basics in vb that I know.  There's no sub here and the page you linked to doesn't show one, either, so not sure how to apply this into an actual working macro format.

    I'll come back to this.  Would be handy to know how to find the actual path of a folder without an addin I can't install (at work, PCs locked up tight, and rightly so).

    Cheers and thanks!

    Friday, November 13, 2015 3:51 PM
  • If you custom folder is on the same level as your default Tasks folder (and the Inbox), all you need to do is go one level up to the root folder and then retrieve the subfolder:

    Set oFolder = Application.Session.GetDefaultFolder(olFolderTasks).Parent.Folders('Your Folder Name')


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Friday, November 13, 2015 8:56 PM
  • Dmitry, that did it! Thank you! I had only a small experience with this sort of thing (folder and subfolder but of different Outlook items) and had never really worked with them before.  But now I have a macro that can be customized to open 3 different types of Task folders:

    '------------------------------------------------------------------------------
    '  Open TASKS folders, code for (some info:  http://www.slipstick.com/developer/code-samples/shortcut-open-outlook-folders/):
    Sub TASKS_open_in_new_window()
        Dim oFolder As Outlook.Folder
            Set oFolder = Application.Session.GetDefaultFolder(olFolderTasks).Parent.Folders("TASKS (Folder Paths)") ' opens custom    'Tasks' _FOLDER_ (same level as Inbox).
    '        Set oFolder = Application.Session.GetDefaultFolder(olFolderTasks)                                       ' opens _DEFAULT_ 'Tasks' folder.
    '        Set oFolder = Application.Session.GetDefaultFolder(olFolderTasks).Folders("TestTasks")                  ' opens custom    'Tasks' _SUB_folder of the default 'Tasks' folder.
        oFolder.Display
    End Sub
    '------------------------------------------------------------------------------

    I know others will find this helpful at some point.

    Thank you, everyone!

    Cheers!

    Friday, November 13, 2015 9:24 PM