【发布时间】:2020-10-06 03:31:11
【问题描述】:
从 W7 上的 Office 2010 升级到 W10 上的 Office 365 后,以下代码停止工作。
Sub readbodytest()
Dim OL As Outlook.Application
Dim DIB As Outlook.Folder
Dim i As Object 'Outlook.ReportItem
Dim Filter As String
Set OL = CreateObject("Outlook.Application")
Set DIB = OL.Session.GetDefaultFolder(olFolderInbox)
Const PR_SENT_REPRESENTING_EMAIL_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x0065001E"
Filter = "@SQL=" & _
"""" & PR_SENT_REPRESENTING_EMAIL_ADDRESS & """ ci_phrasematch 'mailer-daemon' OR " & _
"""" & PR_SENT_REPRESENTING_EMAIL_ADDRESS & """ ci_phrasematch 'postmaster' OR " & _
"urn:schemas:httpmail:subject ci_phrasematch 'undeliverable' OR " & _
"urn:schemas:httpmail:subject ci_phrasematch 'returned'"
For Each i In DIB.Items.Restrict(Filter)
Debug.Print i.Body '<< Code fails here
Next
Set i = Nothing
Set DIB = Nothing
Set OL = Nothing
End Sub
它返回运行时错误-2147467259“对象'_MailItem'的方法'Body'失败”
代码直接在outlook VBA中运行时有效,但在外部运行时无效。
代码的目的是对返回的邮件进行批量审查,将电子邮件正文中的信息与数据库中的记录相匹配,并更新数据库以记录失败。
在我重新编写代码以反向运行之前看看是否有人有任何建议(例如,从 Outlook VBA 到数据库;而不是数据库试图从 Outlook 中检索它)
【问题讨论】: