Share via


Outlook) (PropertyAccessor 物件

會提供在物件上建立、取得、設定和刪除屬性的能力。

註解

使用 PropertyAccessor 物件來取得及設定未在 Outlook 物件模型中明確公開的專案層級屬性,或是下列非專案物件的屬性: AddressEntryAddressListAttachmentExchangeDistributionListExchangeUserFolderRecipientStore

若要取得或設定多個自訂屬性,請使用 PropertyAccessor 物件,而不是 UserProperties 物件,以獲得更好的效能。

如需使用 PropertyAccessor 物件的詳細資訊,請參閱屬性概觀

範例

下列程式碼範例示範如何使用 PropertyAccessor.GetProperty 方法來讀取屬於 MailItem 但未在 Outlook 物件模型中公開的 MAPI 屬性, PR_TRANSPORT_MESSAGE_HEADERS

Sub DemoPropertyAccessorGetProperty() 
 
 Dim PropName, Header As String 
 
 Dim oMail As Object 
 
 Dim oPA As Outlook.PropertyAccessor 
 
 'Get first item in the inbox 
 
 Set oMail = _ 
 
 Application.Session.GetDefaultFolder(olFolderInbox).Items(1) 
 
 'PR_TRANSPORT_MESSAGE_HEADERS 
 
 PropName = "http://schemas.microsoft.com/mapi/proptag/0x007D001E" 
 
 'Obtain an instance of PropertyAccessor class 
 
 Set oPA = oMail.PropertyAccessor 
 
 'Call GetProperty 
 
 Header = oPA.GetProperty(PropName) 
 
 Debug.Print (Header) 
 
End Sub

下一個程式碼範例示範 PropertyAccessor.SetProperties 方法如何設定多個屬性的值。 如果屬性不存在,只要父物件支援這些屬性的建立,SetProperties 就會建立屬性。 如果物件支援明確 Save 作業,在呼叫明確 Save 作業時,屬性會儲存至物件。 如果物件不支援明確的 Save 作業,在呼叫 SetProperties 時,屬性會儲存至物件。

Sub DemoPropertyAccessorSetProperties() 
 
 Dim PropNames(), myValues() As Variant 
 
 Dim arrErrors As Variant 
 
 Dim prop1, prop2, prop3, prop4 As String 
 
 Dim i As Integer 
 
 Dim oMail As Outlook.MailItem 
 
 Dim oPA As Outlook.PropertyAccessor 
 
 'Get first item in the inbox 
 
 Set oMail = _ 
 
 Application.Session.GetDefaultFolder(olFolderInbox).Items(1) 
 
 'Names for properties using the MAPI string namespace 
 
 prop1 = "http://schemas.microsoft.com/mapi/string/" & _ 
 
 "{FFF40745-D92F-4C11-9E14-92701F001EB3}/mylongprop" 
 
 prop2 = "http://schemas.microsoft.com/mapi/string/" & _ 
 
 "{FFF40745-D92F-4C11-9E14-92701F001EB3}/mystringprop" 
 
 prop3 = "http://schemas.microsoft.com/mapi/string/" & _ 
 
 "{FFF40745-D92F-4C11-9E14-92701F001EB3}/mydateprop" 
 
 prop4 = "http://schemas.microsoft.com/mapi/string/" & _ 
 
 "{FFF40745-D92F-4C11-9E14-92701F001EB3}/myboolprop" 
 
 PropNames = Array(prop1, prop2, prop3, prop4) 
 
 myValues = Array(1020, "111-222-Kudo", Now(), False) 
 
 'Set values with SetProperties call 
 
 'If the properties don't exist, then SetProperties 
 
 'adds the properties to the object when saved. 
 
 'The type of the property is the type of the element 
 
 'passed in myValues array. 
 
 Set oPA = oMail.PropertyAccessor 
 
 arrErrors = oPA.SetProperties(PropNames, myValues) 
 
 If Not (IsEmpty(arrErrors)) Then 
 
 'Examine the arrErrors array to determine if any 
 
 'elements contain errors 
 
 For i = LBound(arrErrors) To UBound(arrErrors) 
 
 'Examine the type of the element 
 
 If IsError(arrErrors(i)) Then 
 
 Debug.Print (CVErr(arrErrors(i))) 
 
 End If 
 
 Next 
 
 End If 
 
 'Save the item 
 
 oMail.Save 
 
End Sub

方法

名稱
BinaryToString
DeleteProperties
DeleteProperty
GetProperties
GetProperty
LocalTimeToUTC
SetProperties
SetProperty
StringToBinary
UTCToLocalTime

屬性

名稱
Application
Class
Parent
Session

另請參閱

Outlook 物件模型參考屬性Accessor 物件成員

支援和意見反應

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