英文:
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?
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论