【发布时间】:2016-06-24 09:48:36
【问题描述】:
我想在我的所有 Outlook 中搜索对话中的最新消息(我使用主题名称作为搜索键)。
这条最新消息可以在收件箱、已发送邮件、收件箱的子文件夹、收件箱的子文件夹中(任何地方)。
我可以通过一些非常繁琐的代码来实现这一点,遍历每个主要文件夹的每一级,但这种方法不仅非常混乱,我无法确定这个找到的消息是否是这次对话中最新的。
我有以下代码,其中
--> 在收件箱中搜索“searchKey”
--> 如果在收件箱文件夹中找到,回复它
--> 如果没有,它会移动到收件箱的子文件夹中,并继续相同的过程
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim olFldr As MAPIFolder
Dim olMail ' As Outlook.MailItem
Dim i As Integer
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set olFldr = Fldr
tryAgain:
For Each olMail In olFldr.Items
If InStr(olMail.Subject, searchKey) <> 0 Then
Set ReplyAll = olMail.ReplyAll
With ReplyAll
.HTMLBody = Msg & .HTMLBody
emailReady = True
.Display
End With
End If
Next olMail
If Not emailReady Then
i = i + 1
If i > Fldr.Folders.Count Then
MsgBox ("The email with the given subject line was not found!")
Exit Sub
Else
Set olFldr = Fldr.Folders(i)
GoTo tryAgain
End If
End If
此代码可能会令人困惑且冗长,因此如果您需要任何说明,请告诉我。
问题是:我如何在所有 Outlook 中进行搜索,而无需手动遍历每个文件夹/子文件夹/子子文件夹...没有这种方法,并在特定对话中找到最后一条消息?或者,至少,我怎样才能优化这段代码,这样我就不会错过任何文件夹,并且知道这些电子邮件的发送日期和时间?
【问题讨论】: