locked
Expanding summary tasks in master project file (VBA) RRS feed

  • Question

  • In Project 2013 have a master project file with several projects linked as subprojects. I want to import all tasks into an Excel range as described in vvv.clearlyandsimply.com/clearly_and_simply/2009/01/bring-your-tasks-in-a-row.html. The problem is that if the masterfile is saved with collapsed summary tasks, only these summary tasks are imported. So, I added the following code in the loop that loops throught the tasks in the masterfile to expand the tasks before importing:

    For Each objTask In objProj.Tasks
        If objTask.Summary Then
           Application.Wait (Now + TimeValue("0:00:10"))
           objProjApp.OutlineShowAllTasks
           objProjApp.OutlineShowSubTasks
           objProjApp.OutlineShowTasks
           OutlineNumber:=pjTaskOutlineShowLevel9
        End If

    This does not work. The wait 10s. was added to allow Project to open the subproject, but this did not resolve the issue.

    Any ideas? Thanks in advance.

    Friday, December 18, 2015 1:03 PM

Answers

  • Huismu5,

    When I write macros to work with master projects I normally include the following statement:

    OutlineShowTasks expandinsertedprojects:=True

    In a master file, when the outline is expanded the subprojects are opened in the background which is a lot quicker than opening each subproject in the foreground.

    It is important to understand that in a linked master, the subprojects are not actually part of the master, rather the master contains pointers to each of the individual subprojects. If you use the above statement to expand the master you can use foreground processing, (i.e. operate on objects in the active view), to SelectAll and then loop through all tasks in the ActiveSelection collection. If you want to use background processing, (i.e. operate on objects independent of the active view), then you would need to loop through all tasks in the master, which will only include those tasks that actually belong to the master, and switch to Subprojects(index).SourceProject.Tasks at each summary line insertion point in the master.

    John


    • Edited by John - Project Saturday, December 19, 2015 5:01 PM details
    • Marked as answer by Huismu5 Friday, January 8, 2016 9:04 AM
    Friday, December 18, 2015 4:00 PM

All replies

  • Subprojects aren't the same as summary tasks. You need to iterate through the top level, moving down to the subprojects and processing them as you encounter them. You may get prompted to open the files as you go.

    Public Sub ProcessTopLevel(p As Project)
        Dim t As Task
        Debug.Print p.Name
        For i = 1 To p.Tasks.Count ' for some reason you have to use this iterator here
            Set t = p.Tasks(i)
            ' do something with t
            Debug.Print t.ID & "(" & t.Name & ")"
            If t.Subproject <> "" Then
                ProcessLowerLevel p.Subprojects(t.Name).SourceProject
            End If
        Next
    End Sub

    Sub ProcessLowerLevel(p As Project)
        Debug.Print p.Name
        Dim t As Task
        For Each t In p.Tasks
            ' do something with t
            Debug.Print t.ID & "(" & t.Name & ")"
        Next
    End Sub


    • Edited by Bill.B_ Friday, December 18, 2015 3:49 PM
    Friday, December 18, 2015 3:21 PM
  • Huismu5,

    When I write macros to work with master projects I normally include the following statement:

    OutlineShowTasks expandinsertedprojects:=True

    In a master file, when the outline is expanded the subprojects are opened in the background which is a lot quicker than opening each subproject in the foreground.

    It is important to understand that in a linked master, the subprojects are not actually part of the master, rather the master contains pointers to each of the individual subprojects. If you use the above statement to expand the master you can use foreground processing, (i.e. operate on objects in the active view), to SelectAll and then loop through all tasks in the ActiveSelection collection. If you want to use background processing, (i.e. operate on objects independent of the active view), then you would need to loop through all tasks in the master, which will only include those tasks that actually belong to the master, and switch to Subprojects(index).SourceProject.Tasks at each summary line insertion point in the master.

    John


    • Edited by John - Project Saturday, December 19, 2015 5:01 PM details
    • Marked as answer by Huismu5 Friday, January 8, 2016 9:04 AM
    Friday, December 18, 2015 4:00 PM
  • Thank you John! Your suggestion made the difference.
    Friday, January 8, 2016 9:04 AM
  • Huismu5,

    You're welcome and thanks for the feedback.

    John

    Friday, January 8, 2016 3:50 PM