Share via


Outlook) (NameSpace.CompareEntryIDs 方法

會傳回 Boolean 值,指出兩個項目 ID 值是否參照相同的 Outlook 項目。

語法

expressionCompareEntryIDs( _FirstEntryID_ , _SecondEntryID_ )

表達 會傳回 NameSpace 物件的運算式。

參數

名稱 必要/選用 資料類型 描述
FirstEntryID 必要 字串 要比較的第一個項目 ID
SecondEntryID 必要 字串 要比較的第二個項目 ID

傳回值

如果項目 ID 值參照相同的 Outlook 項目則為 True,否則為 False

註解

因為可以用兩個不同的二進位值來代表一個物件,所以不能直接比較項目識別碼。 使用這個方法來判斷兩個項目識別碼是否代表相同的物件。

範例

下列 Visual Basic for Applications (VBA) 範例會使用CompareEntryIDs方法,比較與指定AppointmentItem物件的召集人相關聯的專案識別碼與指定Recipient物件的專案識別碼,如果召集人和指定的收件者代表相同的使用者,則會傳回True

Function IsRecipientTheOrganizer( _ 
 
 ByVal Appt As Outlook.AppointmentItem, _ 
 
 ByVal Recipient As Outlook.Recipient) As Boolean 
 
 
 
 Dim objAddrEntry As Outlook.AddressEntry 
 
 Dim objPropAc As Outlook.PropertyAccessor 
 
 Dim strOrganizerEntryId As String 
 
 Dim bytResult() As Byte 
 
 Dim objRecipientUser As Outlook.ExchangeUser 
 
 Dim objOrganizerUser As Outlook.ExchangeUser 
 
 Dim blnReturn As Boolean 
 
 
 
 'Property tag for Organizer EntryID 
 
 Const PR_SENT_REPRESENTING_ENTRYID As String = _ 
 
 "http://schemas.microsoft.com/mapi/proptag/0x00410102" 
 
 
 
 ' Retrieve an AddressEntry object reference for the 
 
 ' specified recipient. 
 
 Set objAddrEntry = Recipient.AddressEntry 
 
 
 
 ' If the address entry represents an Exchange user 
 
 ' or Exchange remote user, retrieve an 
 
 ' ExchangeUser object reference for the sender and 
 
 ' compare the EntryID value of that object with 
 
 ' the EntryID of the specified recipient. 
 
 If objAddrEntry.AddressEntryUserType = _ 
 
 OlAddressEntryUserType.olExchangeUserAddressEntry _ 
 
 Or objAddrEntry.AddressEntryUserType = _ 
 
 OlAddressEntryUserType.olExchangeRemoteUserAddressEntry Then 
 
 
 
 ' Attempt to retrieve an ExchangeUser 
 
 ' object reference for the specified 
 
 ' recipient. 
 
 Set objRecipientUser = objAddrEntry.GetExchangeUser() 
 
 
 
 If objRecipientUser Is Nothing Then 
 
 ' An Exchange user could not be retrieved 
 
 ' for the specified recipient. 
 
 blnReturn = False 
 
 Else 
 
 ' Retrieve the EntryID property value of the organizer. 
 
 ' The Organizer property of the AppointmentItem object only 
 
 ' contains a string representation of the name of the 
 
 ' organizer, so the PR_SENT_REPRESENTING_ENTRYID property value 
 
 ' is instead retrieved, using the PropertyAccessor object 
 
 ' associated with the appointment item. 
 
 Set objPropAc = Appt.PropertyAccessor 
 
 bytResult = objPropAc.GetProperty( _ 
 
 PR_SENT_REPRESENTING_ENTRYID) 
 
 
 
 If Not IsEmpty(bytResult) Then 
 
 ' Convert the binary value retrieved from the 
 
 ' PR_SENT_REPRESENTING_ENTRYID property into 
 
 ' a string value for comparison. 
 
 strOrganizerEntryId = _ 
 
 objPropAc.BinaryToString(bytResult) 
 
 
 
 ' Attempt to retrieve an ExchangeUser 
 
 ' object reference for the organizer. 
 
 Set objOrganizerUser = Appt.Application.Session. _ 
 
 GetAddressEntryFromID(strOrganizerEntryId).GetExchangeUser() 
 
 
 
 If objOrganizerUser Is Nothing Then 
 
 ' An Exchange user could not be retrieved 
 
 ' for the organizer. 
 
 blnReturn = False 
 
 Else 
 
 ' Compare the EntryIDs of the organizer 
 
 ' and the specified recipient. 
 
 blnReturn = Appt.Application.Session. _ 
 
 CompareEntryIDs( _ 
 
 objRecipientUser.ID, _ 
 
 objOrganizerUser.ID) 
 
 End If 
 
 End If 
 
 End If 
 
 End If 
 
 
 
EndRoutine: 
 
 ' Clean up 
 
 Set objOrganizerUser = Nothing 
 
 Set objRecipientUser = Nothing 
 
 Set objAddrEntry = Nothing 
 
 Set objPropAc = Nothing 
 
 
 
 ' Return the results. 
 
 IsRecipientTheOrganizer = blnReturn 
 
 
 
 Exit Function 
 
 
 
ErrRoutine: 
 
 Debug.Print Err.Number & " - " & Err.Description, _ 
 
 vbOKOnly Or vbCritical, _ 
 
 "IsRecipientTheOrganizer" 
 
 
 
 GoTo EndRoutine 
 
End Function

另請參閱

NameSpace 物件

支援和意見反應

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