Resource.SetField 方法 (Project)
會設定指定之資源自訂欄位的值。
語法
expression. SetField
( _FieldID_
, _Value_
)
表達 代表 Resource 物件的變數。
參數
名稱 | 必要/選用 | 資料類型 | 描述 |
---|---|---|---|
FieldID | 必要 | Long | 為本機自訂欄位可以是 PjField 常數的資源自訂欄位。 企業自訂欄位,使用 FieldNameToFieldConstant 方法來取得 FieldID。 |
Value | 必要 | String | 欄位的值。 |
範例
下列範例會示範如何使用 SetField 方法和 GetField 方法搭配 FieldNameToFieldConstant 和 FieldConstantToFieldName 方法 Resource 物件的存取企業資源自訂欄位。
若要使用範例,請使用 Project Web App 來建立企業資源文字自訂欄位 (名稱可以是 TestEntResText)。
以重新啟動 Project Professional 的 Project Server 設定檔,使其包含新的自訂欄位。
建立專案,從企業資源建立團隊,然後將資源分派給第一個任務。
TestEnterpriseResourceCF 巨集會使用 FieldNameToFieldConstant 方法來尋找 resourcefield 數字,例如,205553667。
巨集會使用 GetField 方法,在訊息方塊中顯示數字和文字值。
巨集會使用 SetField 方法設定為自訂欄位的新值。
巨集會使用 FieldConstantToFieldName 方法,來取得欄位名稱,然後另一個訊息方塊中顯示的欄位名稱和新的值。
Sub TestEnterpriseResourceCF()
Dim resourceField As Long
Dim resourceFieldName As String
Dim resourceFieldValue As String
Dim message As String
resourceField = FieldNameToFieldConstant("TestEntResText", pjResource)
' Show the enterprise resource field number and old value.
message = "Enterprise resource field number: " & resourceField & vbCrLf
resourceFieldValue = ActiveProject.Tasks(1).Assignments(1).Resource.GetField(resourceField)
If resourceFieldValue = "" Then resourceFieldValue = "[No value]"
MsgBox message & "Field value: " & resourceFieldValue
' Set a value for the enterprise resource custom field.
' Use either the Resources collection or the Assignments collection
' to access the resource custom field.
' Here, use the Assignments collection.
ActiveProject.Tasks(1).Assignments(1).Resource.SetField _
FieldID:=resourceField, Value:="This is a new value."
' For a demonstration, get the field name from the number,
' and then verify the new value.
resourceFieldName = FieldConstantToFieldName(resourceField)
' Here, use the Resources collection to access the custom field.
resourceFieldValue = ActiveProject.Resources(1).GetField(resourceField)
message = "New value for field: " & resourceFieldName & vbCrLf
MsgBox message & "Field value: " & resourceFieldValue
End Sub
如需使用本機資源自訂欄位的範例,請參閱 GetField 方法。
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。