【问题标题】:Getting Alias from items in Outlook AddressBook with VBA使用 VBA 从 Outlook 通讯簿中的项目获取别名
【发布时间】:2023-02-09 02:46:58
【问题描述】:

我下面的代码在 Debug.Print(oExuser.Alias) 处出现以下错误,为什么?

子测试()

Dim AliasName, FullName As String
Dim outlookApp As Outlook.Application
Dim myNameSpace As Outlook.nameSpace
Dim myAddrList As AddressList
Dim myAddrEntries As AddressEntries
Dim myAddrEntry As Outlook.AddressEntry
Dim myAlias As Object
Dim oExUser As Outlook.ExchangeUser

Set outlookApp = New Outlook.Application
Set myNameSpace = outlookApp.GetNamespace("MAPI")
Set myAddrList = myNameSpace.GetGlobalAddressList()


Set myAddrEntries = myAddrList.AddressEntries
Set myAddrEntry = myAddrEntries.Item(1)

Set oExUser = myAddrEntry.GetExchangeUser

Debug.Print (oExUser.Alias)

End Sub

【问题讨论】:

    标签: vba outlook exchange-server addressbook office-automation


    【解决方案1】:

    您必须连接到 Exchange 服务器才能使用 AddressEntry.GetExchangeUser 方法。以下代码仅对 Exchange 帐户有意义:

    Set oExUser = myAddrEntry.GetExchangeUser
    
    Debug.Print (oExUser.Alias)
    

    如果 Alias 对象尚未实现或不存在此属性,则 Alias 属性返回一个空字符串。

    【讨论】:

      【解决方案2】:

      您需要检查返回的 ExchangeUser 对象 (oExUser) 是否不为空。对于非 Exchange(例如 SMTP)地址条目,即使您在当前 Outlook 配置文件中有 Exchange,它也将为空:

      If not (oExUser Is Nothing) Then
          Debug.Print (oExUser.Alias)
      End If
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多