Project) (Application.ResourceAssignment 方法

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

語法

運算式。資源分配 (資源、作業)

expression 代表 Application 物件的變數。

參數

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

備註 如果單位值中包含千位分隔符號或小數點分隔符號,Project 將不會指派資源。
作業 選用 Long 如果省略 [作業] ,Project 會將資源指派給選取的任務。 預設值為 pjAssign 。 可以是其中一個 PjResAssignOperation 常數
With 選用 字串 OperationpjReplace 常數一起使用時,可指定取代所選任務資源的資源名稱。

PjResAssignOperation 常數

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

傳回值

布林值

註解

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

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

注意事項

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

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

範例

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

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 支援與意見反應