none
How to add new assignment in a sub-project of a Master Project Plan in MSP VBA RRS feed

  • Question

  • Hi,

    I have written the following sample code to add a new assignment for the resource with id 1 to the current active task:

    Sub testAddAssignment()
         ActiveCell.Task.Assignments.Add ResourceID:=1
    End Sub

    If I execute the code above for a standard (non master-plan) project file, then the code works fine.

    However, if I execute the code above for a sub-project included in a Master Project Plan like the following
    enter image description here

    then I get the following error message:
    enter image description here

    Monday, January 2, 2017 12:26 AM

Answers

  • Roberto,

    If you're already operating in foreground mode, (i.e. selecting tasks), then I'm not sure why you would want to use VBA to assign resources (i.e. you've manually selected the task, why not manually assign the resource?). Nonetheless, here is the syntax to assign the resource "bill" at a unit level of 1 to the currently selected task.

    ResourceAssignment resources:="bill(1)",operation:=pjAssign

    Hope this helps.

    John

    Tuesday, January 3, 2017 4:00 PM

All replies

  • Roberto,

    Here's the problem. In a dynamic master the subprojects are not actually part of the master, rather, the master contains pointers to each individual subproject. This is evidenced by the fact that the ID numbers in the master are not continuous but restart for each subproject. Unless other tasks are added directly to the master, the only tasks in the master are the summary line insertion points for each subproject

    Since the subproject tasks are not in the master VBA code must reference them as follows. This references the first task of the first subproject

    activeproject.Subprojects(1).SourceProject.Tasks(1)

    Then to add an assignment to using resource ID 1 at a unit level of 1, use the following:

    activeproject.Subprojects(1).SourceProject.Tasks(1).Assignments.add taskID:=1,resourceID:=1,units:=1

    Hope this helps.

    John

    Monday, January 2, 2017 1:28 AM
  • John,

    Thank you for you answer.

    I know do understand how to add an assignment to the n_th task of a sub project, but it is still unclear to me how to add an assignment to the Task currently selected: ActiveCell.Task?

    Regards,

    Roberto

    Tuesday, January 3, 2017 4:03 AM
  • Roberto,

    If you're already operating in foreground mode, (i.e. selecting tasks), then I'm not sure why you would want to use VBA to assign resources (i.e. you've manually selected the task, why not manually assign the resource?). Nonetheless, here is the syntax to assign the resource "bill" at a unit level of 1 to the currently selected task.

    ResourceAssignment resources:="bill(1)",operation:=pjAssign

    Hope this helps.

    John

    Tuesday, January 3, 2017 4:00 PM