none
Master Project & sub Project Macro Error : Argument Value is not Valid RRS feed

  • Question

  • Hi,

    What is wrong with this Code???

    I have a Master Project and Some Sub Projects, and I am suppose to loop through it in reverse direction... But i am getting an error on the Highlighted Line "Argument value is not valid"

    Here ActiveProject. Tasks.Count shows =40 Tasks But when i loop through the For each t in activeproject.Tasks it shows 2857 Tasks and when i loop in the reverse direction it throws an error

    Sub test()
    Dim t As Task
    Dim i As Integer
    Dim icnt As Long
    Debug.Print CStr(ActiveProject.Tasks.Count)
    For Each t In ActiveProject.Tasks
        Debug.Print "OLD" & "-->" & t.Name
        i = i + 1
    Next t
    For icnt = i To 1 Step -1
        Debug.Print "New" & "-->" & ActiveProject.Tasks(icnt).Name
    Next icnt
    End Sub


    Thanks, Parth


    • Edited by Parth Rawal Friday, September 21, 2012 8:03 AM
    Friday, September 21, 2012 8:03 AM

All replies

  • Hi Parth,

    I had to test it myself to believe it. This is clearly a bug in the For Each statement.

    I've always known that in a master, activeproject.tasks only counts the tasks IN THE MASTER itself, not in the subprojects. So AFAIK activeproject.tasks in your case is 40 so trying to address task 2857 throws an error: quite normal.

    I know of two ways to worjk arount this: one is to address the tasks in the subprojects (using sourceproject property of subproject) - seems complicated to do this; or use activeselection to loop through in revers order - activeselection doesn't know the difference between activeproject and subprojects.

    Greetings,

    Friday, September 21, 2012 9:42 AM
    Moderator
  • Ok, let me try your solution and will let you know

    Thanks, Parth

    Friday, September 21, 2012 10:44 AM
  • Hi,

    Sorry for the delay in reply, can you please let me know how to make this activeselection  as i guess first of all i have to do selection in the project which selects every row in project plan.


    Thanks, Parth

    Wednesday, September 26, 2012 7:16 AM
  • Hi,

    Make sure all summary tasks are opened, if necessary use OutlineShowAllTasks

    Then application.selectall

    Greetings,

    Wednesday, September 26, 2012 8:27 AM
    Moderator