“对象'_mailItem'的方法'body'失败" Excel和Outlook 2016中的错误 [英] "Method 'body' of object'_mailItem' failed" error in Excel and Outlook 2016

查看:447
本文介绍了“对象'_mailItem'的方法'body'失败" Excel和Outlook 2016中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Excel 2010中编写了一个程序,用于筛选选定的Outlook 2010文件夹中的电子邮件,并从电子邮件(html)正文中提取信息.

I wrote a program in Excel 2010 to sift through emails in a selected Outlook 2010 folder, and pull in information from the email (html) body.

我已更新到Office2016.此后,使用MailItem对象的某些属性时出现错误.我可以将电子邮件的主题拖入Excel,但是某些属性会导致对象'_mailItem的方法'主体'"失败错误(包括.Body和.To属性).

I updated to Office 2016. Since then, I get an error when using certain properties of the MailItem object. I can pull the subject of the email into Excel, but certain properties cause a "method 'body' of object'_mailItem" failed error (including the .Body and .To properties).

下面是代码的简化版本:

Below is a simplified version of the code:

Sub GatherInfo()

Dim ObjOutlook As Object
Dim MyNamespace As Object
Dim FormFolder As Object

Set ObjOutlook = GetObject(, "Outlook Application")
Set MyNamespace = ObjOutlook.GetNamespace("MAPI")
Set FormFolder = MyNamespace.PickFolder

For i = 1 To FormFolder.Items.Count

    Range("A2").Select
    ActiveCell.Value = FormFolder.Items(i).Subject
    ActiveCell.Offset(0, 1).Value = FormFolder.Items(i).To

End Sub

结果是:

运行时错误'-2147467259(80004005)':
对象"_MailItem"的收件人"方法失败

Run-time error '-2147467259(80004005)':
Method 'To' of object'_MailItem' failed

我已经做过一些研究,想知道是否应该归咎于Outlook 2016安全设置. 这是一个在交换服务器上运行的公司电子邮件帐户.您认为这可能会阻止我访问电子邮件的正文/发件人吗?

I've done some research, and wondering if Outlook 2016 security settings could be to blame. This is a corporate email account, running on an exchange server. Do you think that could be preventing me from accessing the body/sender of the email?

奇怪的是,电子邮件的主题属性有效,但正文/收件人属性无效.

It's strange that the subject property of the email works, but not the body/to properties.

我排除的事物:

1)我发送的纯文本和基于html的电子邮件都具有相同的结果.
2)我尝试尽早绑定Outlook对象(Dim ObjOutlook如Outlook.Application等)

1) I've sent both plain text and html based emails with the same result.
2) I've tried binding the Outlook objects early (Dim ObjOutlook as Outlook.Application, etc.)

我确保只有邮件项目,没有日历项目等

I ensured there were only mail items and no calendar items, etc.

它将在第一次击中该项目时跳闸.要分配.如果我在resume next中插入一行,则它将遍历所有电子邮件,但只会记录主题,而不记录.To属性.

It'll trip out the first time it hits the item.To assignment. If I insert a line to resume next then it'll go through all the emails, but will only record the subject and not the .To property.

推荐答案

避免使用多点符号,并检查您是否真的有MailItem对象(也可以具有ReportItemMeetingItem):

Avoid using multiple dot notation and check if you really have a MailItem object (you can also have ReportItem or MeetingItem):

set items = FormFolder.Items
For i = 1 To items.Count
  set item = items.Item(i)
  if item.Class = 43 Then
    Range("A2").Select
    ActiveCell.Value = item.Subject
    ActiveCell.Offset(0, 1).Value = item.To
  End If
  set item = Nothing
next
set items = Nothing

这篇关于“对象'_mailItem'的方法'body'失败" Excel和Outlook 2016中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆