Application.ResourceAssignment method (Project)
Assigns, removes, or replaces the resources of the selected tasks, or changes the number of units for a resource.
expression.ResourceAssignment (Resources, Operation, With)
expression A variable that represents an Application object.
|Resources||Optional||String||The names of the resources to be assigned, removed, or replaced in the selected tasks.
Note Project will not assign a resource if thousands separators or decimal separators are included in the unit values.
|Operation||Optional||Long||If Operation is omitted, Project assigns the resources to the selected tasks. The default value is pjAssign. Can be one of the PjResAssignOperation constants.|
|With||Optional||String||When used with the pjReplace constant for Operation, specifies the names of the resources that replace the resources of the selected tasks.|
|pjAssign||Assigns the specified resources to the selected tasks.|
|pjRemove||Removes the specified resources from the selected tasks.|
|pjReplace||The resources specified by With replace the resources specified by Resources.|
|pjChange||Changes the resource units for the specified resource. This constant can be used only for a single resource.|
You can use the Resources parameter to specify that a resource assignment is requested or demanded when using the Resource Substitution Wizard. For example, the following macro specifies that the assignment of r1 to the selected task is a requested assignment.
Sub RequestAssignment() ResourceAssignment Resources:="r1[100%, R]", Operation:=pjChange, With:="" End Sub
When using the Resources parameter in this way, D specifies "Demand," R specifies "Request," and N specifies "None." In addition, spaces are not allowed between the units value and the Request/Demand value. For example,
Resources:="100%,R" works, but
Resources:="100%, R" does not.
The Resource Substitution Wizard cannot substitute material resources. Therefore, you cannot request or demand a material resource for a particular assignment by using the Resources parameter.
The following example prompts the user for the name of a resource, and then assigns that resource to the selected tasks.
Sub AssignResourceToSelectedTasks() Dim Entry As String ' The name of the resource to add to selected tasks Dim R As Resource ' Resource object used in For Each...Next loop Dim Found As Boolean ' Whether or not the resource is in the active project Entry = InputBox$("Enter the name of the resource you want to add to the selected tasks.") ' Assume resource doesn't exist in the active project. Found = False ' Look for the resource. For Each R In ActiveProject.Resources If Entry = R.Name Then Found = True Next R ' If the resource is found, then assign it to selected tasks. If Found Then ResourceAssignment Resources:=Entry, Operation:=pjAssign ' Otherwise, tell user the resource doesn't exist. Else MsgBox ("There is no resource in the active project named " & Entry & ".") End If End Sub
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.