【发布时间】:2014-11-22 11:09:44
【问题描述】:
我正在尝试使用 VBA 脚本从收件箱中的电子邮件中提取信息到 Excel 电子表格中:
'Subject
'To Address
'From Address
'CC Addresses
对于已经离开组织并且不再在 O365 中的发件人,它会失败。
这是代码位:
Function X400toSMTP(strAdr As String) As String
Dim olkRcp As Outlook.Recipient, olkUsr As Outlook.ExchangeUser
Set olkRcp = Session.CreateRecipient(strAdr)
If olkRcp.AddressEntry = Empty Then
X400toSMTP = strAdr
ElseIf olkRcp.AddressEntry.AddressEntryUserType = olExchangeUserAddressEntry Then
olkRcp.Resolve
Set olkUsr = olkRcp.AddressEntry.GetExchangeUser
X400toSMTP = olkUsr.PrimarySmtpAddress
End If
Set olkRcp = Nothing
Set olkUsr = Nothing
End Function
我运行了调试,它在AddressEntry 停止:The attempted operation failed. An object could not be found
我正在尝试找到一种方法,让脚本为那些在 O365 上找不到的发件人留空地址字段,并进一步处理收件箱中的其余项目。
我尝试了以下方法:
If IsNull(olkRcp.AddressEntry) Then
X400toSMTP = strAdr
但地址条目仍然出现相同的错误。
我只是一个 VBA 菜鸟,所以非常感谢您的建议。
非常感谢!
【问题讨论】:
-
你可以写
if olkRcp.AddressEntry is nothing then,或者,if isempty(olkRcp.AddressEntry) then,或者if olkRcp.AddressEntry="" then -
非常感谢,帕特里克!我已经尝试过这些,但它仍然给我错误。也许值得一提的是,我在共享邮箱上运行它。我在收件箱中的一个子文件夹上尝试了该脚本,但它并没有在离开者地址处停止,而是在我知道它有效的某个分发列表处停止。我也尝试启用“下载共享文件夹”,但仍然无法用于共享邮箱。