vba - 是否可以找到相关的电子邮件并在后台循环结果?
问题描述
我想查找与我当前选择的电子邮件相关的电子邮件。然后我想循环结果。
使用ActiveExplorer.Search
需要一点时间,同时代码会继续运行。所以它不会返回任何结果,因为加载仍在后台发生,我猜。
所以我的问题是:
- 我如何找到相关的电子邮件?
- 如何循环搜索结果(在后台)?
要查找相关电子邮件,可能是这样的:
Sub FindRelatedEmails()
Dim ns As Outlook.NameSpace
Set ns = myOlApp.GetNamespace("MAPI")
Dim oMail As Outlook.MailItem
Set oMail = ActiveExplorer.Selection.Item(1)
Dim strFrom As String
strFrom = oMail.SenderName
Dim strSubject As String
strSubject = oMail.ConversationTopic
Dim myOlApp As New Outlook.Application
Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderInbox)
Dim txtSearch As String
txtSearch = "[Konversation]:=""" & strSubject & """"
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders
' Problem occurs below, since the code keeps running but the search results haven't loaded yet.
myOlApp.ActiveExplorer.SelectAllItems
Dim i As Long
For i = ActiveExplorer.Selection.Count To 1 Step -1
Dim Item As MailItem
Set Item = ActiveExplorer.Selection.Item(i)
Debug.Print Item.Subject, Item.Sender, Item.Parent.FolderPath
Next
Set ns = Nothing
Set oMail = Nothing
Set myOlApp = Nothing
Set Item = Nothing
End Sub
解决方案
推荐阅读
- node.js - MongoDb $merge 没有向集合添加/更新数据
- javascript - 使用 as 进行转换时,React 中的 Tsx 编译错误
- dart - 为什么 operator ==(Object other) 接受可为空的参数?
- sql - 循环遍历记录集并根据条件将记录写入特定行
- vue.js - Vue.js 计算/移动属性从数据到计算
- encryption - 为什么要对安全文档传输进行两步加密?
- python - Python ROS 与 Anaconda
- node.js - Puppeteer 无法在无头模式下抓取数据,但能够在非无头模式下抓取。怎么修?
- c# - How to connect sql Database with ado.net in Asp.Net Core Mvc 5.0?
- python - Django - 内联表单集验证