Task.ActualCost 屬性 (Project)

取得或設定任務的實際成本。 讀取/寫入 Variant

語法

expressionActualCost

表達 代表 Task 物件的變數。

註解

ActualCost 屬性可以設定 工作分派工作 物件 (但不是為摘要工作) 如果 永遠由 Project 計算實際成本] 核取方塊已清除 [ 專案選項] 對話方塊的 [ 排程] 索引標籤。

實際成本也適用於任務及工作分派。 如果選取 [永遠由 Project 計算實際成本] 核取方塊,Project 就會以資源成本比率表以及指派給任務之資源已完成的實際工時,來計算任務的目前實際成本。 若要以程式設計方式存取資源成本比率表,請使用 CostRateTables 集合。

範例

下列範例會提示使用者輸入作用中專案中,沒有資源之任務的實際成本。 其中假設已經清除 [永遠由 Project 計算實際成本] 核取方塊。

Sub GetActualCostsForTasks() 
 
 Dim Entry As String ' User input 
 Dim T As Task ' Task object used in For Each loop 
 
 ' Count the resources of each task in the active project. 
 For Each T In ActiveProject.Tasks 
 
 ' If a task has no resources, then prompt user for actual cost. 
 If T.Resources.Count = 0 Then 
 
 Do While 1 
 Entry = InputBox$("Enter the cost for " & T.Name & ":") 
 
 ' Exit loop if user enters number or clicks Cancel. 
 If IsNumeric(Entry) Or Entry = Empty Then 
 Exit Do 
 
 ' User didn't enter a number; tell user to try again. 
 Else 
 MsgBox ("You didn't enter a number; try again.") 
 End If 
 Loop 
 
 ' If user didn't click Cancel, assign actual cost to task. 
 If Not StrComp(Entry, Empty, 1) = 0 Then T.ActualCost = Entry 
 End If 
 
 Next T 
 
End Sub

支援和意見反應

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