【发布时间】:2016-02-05 16:22:33
【问题描述】:
我的文件夹中有一些无法送达的电子邮件。我正在尝试浏览文件夹中的每封电子邮件,并通过搜索邮件来提取预期的收件人电子邮件地址。
我有一些适用于常规电子邮件的 VBA 代码,但由于无法投递的不是 Outlook“邮件项目”,它们是 Outlook“报告项目”,我在搜索邮件时遇到问题。搜索功能又空了回来,经过大量研究,似乎“报告项目”实际上没有可以搜索的“主体”。
所有错误报告中的电子邮件在报告中均采用以下格式。
(xxxxxx@xxxxxx.com)
这是我正在使用的代码,它适用于普通邮件项目。
Sub Undeliver()
On Error Resume Next
Set myOlApp = Outlook.Application
Set mynamespace = myOlApp.GetNamespace("MAPI")
'Selects the current active folder to use
Set myfolder = myOlApp.ActiveExplorer.CurrentFolder
'creates excel spreadsheet where data will go
Set xlobj = CreateObject("excel.application")
xlobj.Visible = True
xlobj.Workbooks.Add
'names column a row 1 "email" and column b row 1 "else"
xlobj.Range("a" & 1).Value = "Email"
xlobj.Range("b" & 1).Value = "Else"
'loops through all the items in the current folder selected
For I = 1 To myfolder.Items.Count
Set myitem = myfolder.Items(I)
'selects the body of the current email being searched
msgtext = myitem.Body
'searches the body for the first open parentheses and first close
'parentheses and copies the value in between into an array
delimtedMessage = Replace(msgtext, "(", "###")
delimtedMessage = Replace(delimtedMessage, ")", "###")
'splits the array up into two pieces
messageArray = Split(delimitedMessage, "###")
'this inputs the values of the array into my excel spreadsheet
xlobj.Range("a" & I + 1).Value = messageArray(1)
xlobj.Range("b" & I + 1).Value = messageArray(2)
Next I
End Sub
有谁知道我如何访问报告的消息部分以进行搜索?
【问题讨论】:
-
(我从您的标题中删除了“已解决”。由于您接受了答案,这对于其他有类似问题的人来说是正确的指示。)