共用方式為


Outlook) (UserProperties.Add 方法

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

語法

運算式新增 (名稱類型AddToFolderFieldsDisplayFormat)

表達 代表 UserProperties 物件的 變數。

參數

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

傳回值

代表新屬性的 UserProperty 物件。

註解

您可以藉由呼叫 Outlook 專案或資料夾的 UserProperties.Add 方法或資料夾 的 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 支援與意見反應