从Outlook AddressBook中使用VBA获取项目的别名

huangapple go评论60阅读模式
英文:

Getting Alias from items in Outlook AddressBook with VBA

问题

以下是您代码的问题的翻译部分:

在您的代码中,出现错误的地方是 Debug.Print(oExUser.Alias)。为什么会出错呢?

希望这能帮助您解决问题。如果您需要更多帮助,请随时提问。

英文:

My code below gives me the following error at the Debug.Print(oExuser.Alias), why?

从Outlook AddressBook中使用VBA获取项目的别名

Sub Test()

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

答案1

得分: 1

你必须连接到Exchange服务器才能使用AddressEntry.GetExchangeUser方法。以下代码仅适用于Exchange帐户:

Set oExUser = myAddrEntry.GetExchangeUser

Debug.Print (oExUser.Alias)

如果Alias属性未被实现或者对于ExchangeUser对象不存在,该属性将返回空字符串。

英文:

You have to be connected to the Exchange server to use the AddressEntry.GetExchangeUser method. The following code makes sense only for the Exchange accounts:

Set oExUser = myAddrEntry.GetExchangeUser

Debug.Print (oExUser.Alias)

The Alias property returns an empty string if this property has not been implemented or does not exist for the ExchangeUser object.

答案2

得分: 1

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

如果不是oExUser 为 Nothing    调试.打印oExUser.Alias
结束如果
英文:

You need to check that the returned ExchangeUser object (oExUser) is not null. It will be null for the non-Exchange (e.g., SMTP) address entries even if you have Exchange in the current Outlook profile:

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

huangapple
  • 本文由 发表于 2023年2月8日 19:50:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75385402.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定