1

提前感谢您的帮助...我的 Googleness 今天让我失望了。

我找到了很多关于使用 excel VBA 访问电子邮件信息的资源,并且在大多数情况下我可以让它们工作。但由于某种原因,最关键的部分,即电子邮件的正文,是空白的。

Dim myOlApp As Object, myNameSpace As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myfolders = myNameSpace.Folders
n = 1
Do Until myfolders.Item(n) = "xxxxx"
    n = n + 1
Loop
Set myfolder = myfolders.Item(n)
Set myfolder2 = myfolder.Folders("Inbox")
c = 12
n = 36
For Each Item In myfolder2.Items
    itsj = Item.Subject
    itrt = Item.ReceivedTime
    itbo = Item.Body
    Cells(n, c) = itrt
    Cells(n, c + 1) = itsj
    Cells(n, c + 2) = itbo
    n = n + 1
 Next Item

一切似乎都有效,除了 Item.Body。我得到一个

运行时错误“287”:应用程序定义的或对象定义的错误

查看 .body,或者就此而言:.HTMLBody 或 .RTFBody,在 Locals 视图中,它们都显示了 <> 的值。我尝试了很多来自不同人的不同电子邮件,但结果总是相同。我还在 Locals 文件夹中向下钻取了所有其他对象以直接引用电子邮件并获得相同的结果。我正在使用 2010 Outlook 和 Excel。

谢谢!

4

1 回答 1

0

我对我的没有任何问题,只是它实际上并没有在牢房里放任何东西。所以,我稍微修改了一下并放入了Application.ActiveSheet:

Dim myOlApp As Object, myNameSpace As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myfolders = myNameSpace.Folders
n = 1
Do Until myfolders.Item(n) = "xxxxx"
    n = n + 1
Loop
Set myfolder = myfolders.Item(n)
Set myfolder2 = myfolder.Folders("Inbox")
c = 1
n = 1
For Each Item In myfolder2.Items
    itsj = Item.Subject
    itrt = Item.ReceivedTime
    itbo = Item.Body
    Application.ActiveSheet.Cells(n, c) = itrt
    Application.ActiveSheet.Cells(n, c + 1) = itsj
    Application.ActiveSheet.Cells(n, c + 2) = itbo
    n = n + 1
 Next Item

我在 Office 2010 上。

于 2013-07-10T05:11:36.260 回答