共用方式為


Outlook) 的 PropertyAccessor.GetProperties 方法 (

會取得一維陣列 SchemaNames 指定的屬性值。

語法

expressionGetProperties( _SchemaNames_ )

表達 代表 PropertyAccessor 物件的變數。

參數

名稱 必要/選用 資料類型 描述
SchemaNames 必要 Variant 陣列,其中含有要傳回其值的屬性名稱。 這些屬性是依命名空間參照。 如需詳細資訊,請參閱依命名空間參照屬性

傳回值

變數,表示參數 SchemaNames 中指定的屬性值陣列。 傳回陣列中的元素數目會等於 SchemaNames 陣列中的元素數目。 如果取得特定屬性時發生錯誤,就會在傳回陣列的對應位置中傳回 Err 值。

註解

GetProperties 傳回的陣列可能會含有不同類型的元素,端視要求的屬性類型而定。 GetProperties 傳回的陣列元素類型會與基礎屬性的類型相同。 不過,PT_OBJECT 等特定原始屬性類型不受支援,而且會引發錯誤。 例如,如果您需要將原始屬性類型從 PT_BINARY 轉換為字串,或從 PT_SYSTIME 轉換為當地時間,請使用 Helper 方法 PropertyAccessor.BinaryToStringPropertyAccessor.UTCToLocalTime

如需使用 PropertyAccessor 物件取得屬性的詳細資訊,請參閱 取得和設定屬性的最佳做法

範例

下列程式碼範例示範如何使用 PropertyAccessor 物件來取得 Outlook 專案上未公開的 MAPI 屬性,也就是: PR_SUBJECTPR_ATTR_HIDDENPR_ATTR_READONLYPR_ATTR_SYSTEM。 此程式碼範例會使用 GetProperties 方法在單一呼叫內擷取這些屬性,並指定這些屬性的命名空間參照陣列,然後取得含有每個屬性之原始值的傳回陣列。

Sub DemoPropertyAccessorGetProperties() 
 
 Dim PropNames() As Variant 
 
 Dim myValues As Variant 
 
 Dim i As Integer 
 
 Dim j As Integer 
 
 Dim oMail As Object 
 
 Dim oPA As Outlook.PropertyAccessor 
 
 
 
 'Get first item in the inbox 
 
 Set oMail = _ 
 
 Application.Session.GetDefaultFolder(olFolderInbox).Items(1) 
 
 'PR_SUBJECT, PR_ATTR_HIDDEN, PR_ATTR_READONLY, PR_ATTR_SYSTEM 
 
 PropNames = _ 
 
 Array("http://schemas.microsoft.com/mapi/proptag/0x0037001E", _ 
 
 "http://schemas.microsoft.com/mapi/proptag/0x10F4000B", _ 
 
 "http://schemas.microsoft.com/mapi/proptag/0x10F6000B", _ 
 
 "http://schemas.microsoft.com/mapi/proptag/0x10F5000B") 
 
 'Obtain an instance of a PropertyAccessor object 
 
 Set oPA = oMail.PropertyAccessor 
 
 'Get myValues array with GetProperties call 
 
 myValues = oPA.GetProperties(PropNames) 
 
 For i = LBound(myValues) To UBound(myValues) 
 
 'Examine the type of the element 
 
 If IsError(myValues(i)) Then 
 
 'CVErr returns a variant of subtype error 
 
 Debug.Print (CVErr(myValues(i))) 
 
 ElseIf IsArray(myValues(i)) Then 
 
 propArray = myValues(i) 
 
 For j = LBound(propArray) To UBound(propArray) 
 
 Debug.Print (propArray(j)) 
 
 Next 
 
 ElseIf IsNull(myValues(i)) Then 
 
 Debug.Print ("Null value") 
 
 ElseIf IsEmpty(myValues(i)) Then 
 
 Debug.Print ("Empty value") 
 
 ElseIf IsDate(myValues(i)) Then 
 
 Debug.Print (oPA.UTCToLocalTime(myValues(i))) 
 
 'VB does not have IsBinary function 
 
 ElseIf VarType(myValues(i)) = vbByte Then 
 
 Debug.Print (oPA.BinaryToString(myValues(i))) 
 
 Else 
 
 Debug.Print (myValues(i)) 
 
 End If 
 
 Next 
 
End Sub

另請參閱

PropertyAccessor 物件

支援和意見反應

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