Share via


Application.ResourceAssignment Method

Project Developer Reference

Assigns, removes, or replaces the resources of the selected tasks, or changes the number of units for a resource.

Syntax

expression.ResourceAssignment(Resources, Operation, With)

expression   A variable that represents an Application object.

Parameters

Name Required/Optional Data Type Description
Resources Optional String The names of the resources to be assigned, removed, or replaced in the selected tasks.
Bb213640.vs_note(en-us,office.12).gif  Note
Project will not assign a resource if thousands separators or decimal separators are included in the unit values.
Bb213640.vs_note(en-us,office.12).gif  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 following PjResAssignOperation constants:
ConstantDescription
pjAssignAssigns the specified resources to the selected tasks.
pjRemoveRemoves the specified resources from the selected tasks.
pjReplaceThe resources specified with With replace the resources specified with Resources.
pjChangeChanges the resource units for the specified resource. This constant can be used only for a single resource.
Constant Description
pjAssign Assigns the specified resources to the selected tasks.
pjRemove Removes the specified resources from the selected tasks.
pjReplace The resources specified with With replace the resources specified with Resources.
pjChange Changes the resource units for the specified resource. This constant can be used only for a single resource.
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.

Return Value
Boolean

Remarks

In Microsoft Office Project 2007, 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.

Visual Basic for Applications
  Sub RequestAssignment()
	ResourceAssignment Resources:="r1[100%, R]", Operation:=pjChange, With:=""
End Sub
Bb213640.vs_note(en-us,office.12).gif  Note
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,
Visual Basic for Applications
  Resources:="100%,R"
will work, but
Visual Basic for Applications
  Resources:="100%,  R"
will not.
Visual Basic for Applications
  Resources:="100%,R"
Visual Basic for Applications
  Resources:="100%,  R"

In Office Project 2007, the Resource Substitution Wizard cannot substitute material resources. Therefore, you cannot request or demand a material resource for a particular assignment using the Resources parameter.

Example
The following example prompts the user for the name of a resource, and then assigns that resource to the selected tasks.

Visual Basic for Applications
  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
    <strong class="bterm">ResourceAssignment</strong> Resources:=Entry, Operation:=pjAssign
' Otherwise, tell user the resource doesn't exist.
Else
    MsgBox ("There is no resource in the active project named " &amp; Entry &amp; ".")
End If

End Sub

See Also