共用方式為


Application.ResourceAssignment 方法 (專案)

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

語法

表情ResourceAssignment (資源操作)

expression 代表 Application 物件的變數。

參數

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

便條 若單位值中包含數千個分隔符或十進位分隔符,專案將不會指派資源。
作業 選用 Long 若省略 操作 ,專案會將資源分配給所選任務。 預設值為 pjAssign 。 可以是 PjResAssignOperation 常數之一。
With 選用 字串 當與 pjReplace 常數搭配 Operation 使用時,指定替換所選任務資源的名稱。

PjResAssignOperation 常數

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

傳回值

布林值

註解

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

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

注意事項

當以這種方式使用 資源 參數時, D 指定「需求」, R 指定「請求」 ,N 表示 「無」。此外,單位價值與請求/需求值之間不允許空格。 如範例、 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 支援與意見反應