共用方式為


UserProperties.Add 方法 (Outlook)

UserProperties 集合中建立一個新的使用者屬性。

語法

表情新增 (名稱類型AddToFolderFieldsDisplayFormat)

一個代表 UserProperties 物件的變數。

參數

名稱 必要/選用 資料類型 描述
Name 必要 字串 屬性的名稱。 最大長度為 64 個字元。 名稱中不允許使用字元「[', ']', '_' 和 '#'。
Type 必要 OlUserPropertyType 新屬性的類型。
AddToFolderFields 選用 布林值 如果該屬性會以自訂欄位加入該物品所在的資料夾,那就成立。 此欄位可在資料夾檢視中顯示。 如果該屬性會被加到物品上作為自訂欄位,但不會加入資料夾,則為 False。 預設值為 True
DisplayFormat 選用 Long 會指定屬性將如何在 Outlook 使用者介面中顯示。 此參數可以設定為數個不同列舉中的某個值,這點必須由 Type 參數中所指定的 OlUserPropertyType 常數決定。 如需 TypeDisplayFormat 如何互動的詳細資訊,請參閱 DisplayFormat 屬性

傳回值

一個代表新屬性的 UserProperty 物件。

註解

你可以透過呼叫 UserProperties.Add 方法來定義 Outlook 項目或資料夾,或呼叫 UserDefinedProperties.Add 方法來定義資料夾。

你可以建立由 OlUserPropertyType 枚舉定義的屬性,但以下類型除外: olEnumerationolOutlookInternalolSmartFrom

若要首次設定由 UserProperties.Add 方法建立的屬性,請使用 UserProperty.Value 屬性,取代 PropertyAccessor 物件的 SetPropertiesSetProperty

如果您想要檢視某個項目的自訂屬性,就必須使用 UserProperties.Add 方法來建立該屬性。 由 PropertyAccessor 建立的自訂屬性不支援自訂檢視。

您不能將自訂屬性新增到如 Word、Excel 或 PowerPoint 檔案的 Office 文件項目。 當你嘗試以程式方式將使用者定義欄位加入 DocumentItem 物件時,會收到錯誤訊息。

範例

這個 VBA 範例建立了新的 ContactItem 物件,並新增「LastDateSpokenWith」作為自訂屬性。

Sub AddUserProperty() 
 Dim myItem As Outlook.ContactItem 
 Dim myUserProperty As Outlook.UserProperty 
 
 Set myItem = Application.CreateItem(olContactItem) 
 Set myUserProperty = myItem.UserProperties _ 
 .Add("LastDateSpokenWith", olDateTime) 
 myItem.Display 
End Sub

這個 VBA 範例會建立新的 ContactItem 物件並新增 "Details" 做為使用者屬性。 這個值是透過更改 UserProperty 物件的 Value 屬性來設定的。

Sub AddUserProperty() 
 Dim myItem As Outlook.ContactItem 
 Dim myUserProperty As Outlook.UserProperty 
 
 Set myItem = Application.CreateItem(olContactItem) 
 Set myUserProperty = myItem.UserProperties _ 
 .Add("Details", olText) 
 myUserProperty.Value = "Neighbor" 
 myItem.Display 
End Sub

另請參閱

UserProperties 物件

支援和意見反應

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