共用方式為


Project) (Application.ResourceAssignment 方法

會分派、移除或取代選取之任務的資源,或是變更資源的單位數目。

語法

運算式ResourceAssignment (資源作業具有)

expression 代表 Application 物件的變數。

參數

名稱 必要/選用 資料類型 描述
資源 選用 String 要指派給資源的名稱移除或取代中選取的任務。

注意 如果單位值中包含數千個分隔符號或十進位分隔符號,Project 將不會指派資源。
作業 選用 Long 如果省略 Operation ,Project 會將資源指派給選取的工作。 預設值為 pjAssign 。 可以為其中一個 PjResAssignOperation 常數
With 選用 字串 搭配OperationpjReplace常數使用時,指定取代所選工作資源的資源名稱。

PjResAssignOperation 常數

常數 描述
pjAssign 將指定的資源分派給選取的任務。
pjRemove 從選取的任務中移除指定的資源。
pjReplace With 指定的資源取代 Resources 所指定的 資源
pjChange 修改指定資源的資源單位。 該常數僅指定用於單一資源。

傳回值

布林值

註解

使用 Resources 參數來指定使用資源替代精靈時,要求或要求資源指派。 例如,下列巨集會指定的分派給選取任務的 r1 所要求的工作分派。

Sub RequestAssignment()
    ResourceAssignment Resources:="r1[100%, R]", Operation:=pjChange, With:="" 
End Sub

注意事項

以這種方式使用 Resources 參數時, D 會指定「需求」、 R 指定「要求」, 而 N 則指定「無」。此外,單位值與 Request/Demand 值之間不允許空格。 如範例、 Resources:="100%,R"運作,但 Resources:="100%, R"並不支援。

資源替換精靈無法替換材料資源。 因此,您無法使用 Resources 參數來 要求或要求特定指派的材料資源。

範例

下列範例會為使用者提示資源名稱,然後將該資源分派給選取的任務。

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

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應