我在文件夾中有一些無法投遞的電子郵件。我正在嘗試瀏覽該文件夾中的每封電子郵件,並通過搜索該郵件來提取目標收件人的電子郵件地址。Outlook無法投遞的退回報表項搜索問題,VBA
我有一些VBA代碼在普通電子郵件上工作,但由於無法投遞的不是Outlook「郵件項目」,它們是Outlook「報告項目」,我在搜索郵件時遇到問題。搜索功能迴歸空白,經過大量研究,似乎「報告項目」實際上並沒有可以搜索的「身體」。
報告中的所有錯誤報告中的電子郵件格式如下。
([email protected])
這是我使用的代碼,它對普通郵件項目起作用。
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
有沒有人知道我可以如何訪問報告的消息部分用於搜索目的?
(我刪除了您標題爲「解決」。既然你接受了答案,那就是對他人有類似的問題的正確指示。) – usr2564301