none
VBA Macro OutlineShowTasks Fails RRS feed

  • Question

  • Good afternoon all,

    I'm running into a problem and am hoping you can shed some light on it for me.

    I'm trying to show all tasks via VBA for a consolidated project schedule, but every time I try to run it, I receive the following error:

    Run-time error '-2147417848 (80010108)':

    Method 'OutlineShowTasks' of object '_MSProject' failed.

    My code follows (I need to show all tasks for two schedules, hence the For-Next loop):

        For Each thisProject In Application.Projects
            thisProject.Activate
            Application.SelectAll
            
            If thisProject.Subprojects.count > 0 Then
                Application.OutlineShowTasks ExpandInsertedProjects:=True
            Else
                Application.OutlineShowAllTasks
            End If
        Next thisProject
    

    Here's the screen shot of the error as well:

    OutlineShowTasks Error

    If I try to run the code from Project rather than from the VBA Editor, I receive the following error:

    I'm stumped. Any suggestions?

    Thanks in advance,

    John


    John C. Johnson

    Thursday, August 16, 2012 9:02 PM

Answers

  • Hi,

    Of course you can walk through the task collection without showing the tasks! YYou can even wlk through the tasks collection while showing for instance a resoruce view. Here's a typical example

    For each Job in activeproject.tasks

    if not job is nothing then 'to avoid run time error on an empty line

    ... whatever handleing

    end if 'Nothing

    next Job

    For a master project this would be more complex:

    For each Subp in activeproject.subprojects

    set Subpr=subp.sourceproject

    for each job in subpr.tasks

    if not job is nothing then

    ....

    end if 'Nothing

    next job

    next subp

    BTW, could it be that your outlineshowtasks fails because the active view is a resource view?

    Greetings,

    • Marked as answer by JayCJohnson Friday, August 31, 2012 7:43 PM
    Friday, August 17, 2012 3:18 PM
    Moderator

All replies

  • Hi,

    I cannot reproduce the error on the Ouitlienshowtasks itself; the only thing I find very suspect in your code is your use of This>Project as a variable name, since VBA uses ThisProejct to designate the project the code resides in (fro instance if the module is in the Global.mpt, ThisProject is the Global.mpt). Could you try with a less suspect name such as AProject?

    Greetings,

    Friday, August 17, 2012 7:25 AM
    Moderator
  • Jan,

    Thanks for your reply. I can globally replace the variable name and will do so this morning, but I don't think it's the culprit, as I'm using it in several other macros with no ill effects (my lack of in-depth knowledge of the Project object model notwithstanding).

    A follow-on question: is it possible to traverse the Tasks collection in code without showing all tasks?

    Regards,

    John


    John C. Johnson

    Friday, August 17, 2012 2:32 PM
  • Hi,

    Of course you can walk through the task collection without showing the tasks! YYou can even wlk through the tasks collection while showing for instance a resoruce view. Here's a typical example

    For each Job in activeproject.tasks

    if not job is nothing then 'to avoid run time error on an empty line

    ... whatever handleing

    end if 'Nothing

    next Job

    For a master project this would be more complex:

    For each Subp in activeproject.subprojects

    set Subpr=subp.sourceproject

    for each job in subpr.tasks

    if not job is nothing then

    ....

    end if 'Nothing

    next job

    next subp

    BTW, could it be that your outlineshowtasks fails because the active view is a resource view?

    Greetings,

    • Marked as answer by JayCJohnson Friday, August 31, 2012 7:43 PM
    Friday, August 17, 2012 3:18 PM
    Moderator
  • Good afternoon, and thanks for your reply. I've learned a great deal about the Project object model these past several weeks and appreciate your feedback!

    Regards,

    John


    John C. Johnson

    Friday, August 31, 2012 7:43 PM
  • It is an experience for sure! :-)

    If you ever need to actually show the user all the tasks for some reason do it like this:

    Application.SelectAll
    Application.OutlineShowAllTasks

    There is no reason to loop through the projects to show all the tasks.




    Brian Kennemer - Project MVP
    DeltaBahn Senior Architect
    endlessly obsessing about Project Server…so that you don’t have to.
    Blog | Twitter | LinkedIn

    Friday, August 31, 2012 11:44 PM
    Moderator
  • That's what I thought, too, but I had some hinky results when trying to iterate through the collection - could have been my code. :-)

    John C. Johnson

    Sunday, September 2, 2012 12:16 AM