Excel Userform从alias获取outlook显示名称和电子邮件

Excel Userform从alias获取outlook显示名称和电子邮件,excel,vba,outlook,Excel,Vba,Outlook,我有一个带有3个文本框和1个按钮的用户表单。我想在textbox1 txtPID中放入outlook别名,并在框2和框3 txtName和txtmail中返回显示类型和电子邮件 这似乎连接到outlook并提取信息,但它没有搜索文本框1中给出的别名 Load UsrFrmNewRep Dim olApp As Outlook.Application Dim olNS As Outlook.Namespace Dim olGAL As Outlook.AddressList Dim olMem

我有一个带有3个文本框和1个按钮的用户表单。我想在textbox1 txtPID中放入outlook别名,并在框2和框3 txtName和txtmail中返回显示类型和电子邮件

这似乎连接到outlook并提取信息,但它没有搜索文本框1中给出的别名


Load UsrFrmNewRep

Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olGAL As Outlook.AddressList
Dim olMember As Outlook.AddressEntry
Dim olAliasName As String
Dim exchuser As Outlook.ExchangeUser


Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")
Set olGAL = olNS.AddressLists("Global Address List")

olAliasName = UsrFrmNewRep.txtPID.Value
Set olMember = olGAL.AddressEntries(olAliasName)
Set exchuser = olMember.GetExchangeUser

If Not exchuser Is Nothing Then

UsrFrmNewRep.txtName.Value = exchuser.DisplayType
UsrFrmNewRep.txtEmail.Value = exchuser.PrimarySmtpAddress

End If

End Sub
我肯定我没有正确引用某些东西,我只是不确定是什么


谢谢

使用olNS.CreateRecipientolAliasName/Recipient.Resolve/set olMember=Recipient.AddressEntry代替olGAL.AddressEntry,需要一些尝试和错误,但这完全符合我的要求。