我在 Excel 中有一个名字和姓氏的列表,我想利用该列表使用 Visual Basic 在 Outlook 中查找电子邮件地址。
我正在使用以下 VB 代码:
Private Sub GetAddresses()
Dim o, AddressList, AddressEntry
Dim c As Range, r As Range, AddressName As String
Set o = CreateObject("Outlook.Application")
Set AddressList = o.Session.AddressLists("Global Address List")
Set r = Range("a1:a3")
For Each c In r
AddressName = Trim(c.Value) & ", " & Trim(c.Offset(0, 1).Value)
For Each AddressEntry In AddressList.AddressEntries
If AddressEntry.Name = AddressName Then
c.Offset(0, 2).Value = AddressEntry.Address
Exit For
End If
Next AddressEntry
Next c
End Sub
在实际检索电子邮件地址之前,该代码似乎运行良好。在它匹配一个名称后,它返回以下而不是地址。有谁知道我做错了什么。
/O=Compnay/OU=Company/cn=Recipients/cn=shs
提前感谢您的帮助。