Outlook) (AddressEntry.GetExchangeUser 方法

如果 AddressEntry 屬於 Exchange AddressList 物件,例如全域通訊清單 (GAL) ,則傳回代表 AddressEntry 的 ExchangeUser 物件並對應至 Exchange 使用者。

語法

expression。 GetExchangeUser

運算式 代表 AddressEntry 物件的變數。

傳回值

表示 AddressEntry 的 ExchangeUser 物件。 如果 AddressEntry 物件未對應至 Exchange 使用者,則在 Visual Basic) 中傳回 Null (Nothing。

註解

您必須連線到 Exchange Server 才能使用這個方法。

如果使用此方法傳遞的字串具有類似於現有位址項目的字集,則傳回值可能包含根據傳遞的字串第一個字母相符的項目。

例如,您可以為 Exchange 使用者傳遞字串 “Jack”,該使用者在他的 Outlook 通訊錄中有 “Jai” 的地址項目,但沒有 “Jack”。 即使 Outlook 通訊錄中沒有「傑克」項目,但傳回的電子郵件地址是「Jai」,而不是「Null」。

範例

在下列程式碼範例中,會顯示如何取得 Exchange 全域通訊清單中所有 Exchange 使用者項目的商務電話號碼、辦公室位置及職稱。 它首先使用 AddressList.AddressListType 來尋找全域通訊清單。 針對該 AddressList 上的每個 AddressEntry,它會使用 AddressEntryUserType 來驗證 AddressEntry 是否代表 Exchange 使用者。 找到 Exchange 使用者之後,它會使用 GetExchangeUser 來取得並列印使用者的各種資料片段。

Sub DemoAE() 
 
 Dim colAL As Outlook.AddressLists 
 Dim oAL As Outlook.AddressList 
 Dim colAE As Outlook.AddressEntries 
 Dim oAE As Outlook.AddressEntry 
 Dim oExUser As Outlook.ExchangeUser 
 Set colAL = Application.Session.AddressLists 
 
 For Each oAL In colAL 
    'Address list is an Exchange Global Address List 
    If oAL.AddressListType = olExchangeGlobalAddressList Then 
        Set colAE = oAL.AddressEntries 
        
        For Each oAE In colAE 
            If oAE.AddressEntryUserType = olExchangeUserAddressEntry _ 
               Or oAE.AddressEntryUserType = olExchangeRemoteUserAddressEntry Then 
               
                Set oExUser = oAE.GetExchangeUser 
                Debug.Print (oExUser.JobTitle) 
                Debug.Print (oExUser.OfficeLocation) 
                Debug.Print (oExUser.BusinessTelephoneNumber) 
            End If 
        Next 
    End If 
 Next 
 
End Sub

另請參閱

AddressEntry 物件

支援和意見反應

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