编程方式打开搜索视图

问题描述 投票:0回答:1

我正在寻找一种方式来打开前景编程指定条件搜索视图。我看到其他的问题,比如VBA Search in Outlook,但他们对编程检索搜索结果。

我本质上寻找相同的功能功能区选项留言/编辑/相关:

当我打开通过双击消息上的消息,然后点击“邮件在此会话” enter image description here

列表视图改变

enter image description here

我想能够做到使用VBA宏,但同样的事情,不打开邮件,并用不同的搜索条件

vba outlook outlook-vba
1个回答
0
投票

有两种可能的方式来显示在Outlook的搜索结果:

  1. 从Outlook对象模型中的应用类的AdvancedSearch方法允许执行在Outlook多个文件夹的搜索。在Outlook中使用的AdvancedSearch方法的主要优点是: 搜索在另一个线程中执行。你不需要手动运行另一个线程,因为AdvancedSearch方法在后台自动运行它。 可能搜索的任何项目类型:电子邮件,约会,日历,便笺等在任何位置,即超越特定的文件夹的范围。该限制和Find / FindNext方法可以应用于特定项目集合(查看文件夹类的Outlook中的邮件属性)。 对于DASL查询全面支持(自定义属性可用于搜索太)。您可以在MSDN中的Filtering文章中了解更多关于这一点。为了提高搜索性能,如即时搜索为存储启用,可以使用即时搜索关键字(见IsInstantSearchEnabled类的Store属性)。 最后,你可以在使用搜索类的Stop方法的任何时刻停止搜索过程。 诚然,Search类可以让您保存在搜索文件夹(实际上,它不包含任何物品,只是从范围文件夹项的引用)搜索的结果。你只需要调用在Save事件处理程序Search对象的AdvanvedSearchComplete方法。
  2. 定制Outlook中的文件夹或资源管理器对象的当前视图。该CurrentView属性返回View类的一个实例。见HowTo: Use the View.XML property to filter Outlook items以获取更多信息。

 Dim sFilter As String
 Dim CurrentExplorer As Outlook.Explorer = Nothing
 Dim CurrentView As Outlook.View = Nothing
 Dim CurrentXML As XmlDocument = New XmlDocument
 Dim CurrentFilterNodes, CurrentViewNodes As XmlNodeList
 Dim CurrentFilterNode, CurrentParentNode As XmlNode

 If TextBox1.Text.Length > 0 Then
     If rbtSubject.Checked Then
        sFilter = "urn:schemas:httpmail:subject LIKE '%" + _
        TextBox1.Text.Trim + "%'"
    Else
        sFilter = "urn:schemas:httpmail:textdescription LIKE '%" + _
        TextBox1.Text.Trim + "%'"
    End If

    CurrentExplorer = TryCast(ExplorerObj, Outlook.Explorer)
    If (CurrentExplorer IsNot Nothing) Then
        CurrentView = CurrentExplorer.CurrentView
        If (CurrentView IsNot Nothing) Then
            Try
                CurrentXML.LoadXml(CurrentView.XML)
                CurrentFilterNodes = _
                    CurrentXML.GetElementsByTagName("filter")
                If CurrentFilterNodes.Count > 0 Then
                    For y As Integer = 0 _
                        To CurrentFilterNodes.Count - 1
                        CurrentFilterNode = CurrentFilterNodes(y)
                        If CurrentFilterNode.HasChildNodes Then
                            For i As Integer = _
                            CurrentFilterNode.ChildNodes.Count - 1 _
                                To 0 Step -1
                                CurrentFilterNode.RemoveChild( _
                                    CurrentFilterNode.ChildNodes(i))
                            Next
                        End If
                    Next
                    CurrentFilterNode = CurrentFilterNodes(0)
                    CurrentFilterNode.AppendChild( _
                        CurrentXML.CreateTextNode(sFilter))
                Else
                    CurrentViewNodes = CurrentXML. _
                        GetElementsByTagName("view")
                    If CurrentViewNodes IsNot Nothing Then
                        CurrentParentNode = CurrentViewNodes(0)
                        CurrentFilterNode = CurrentXML. _
                            CreateElement("filter")
                        CurrentParentNode.AppendChild( _
                            CurrentFilterNode)
                        CurrentFilterNode.AppendChild( _
                            CurrentXML.CreateTextNode(sFilter))
                    End If
                End If
                CurrentView.XML = CurrentXML.InnerXml
                CurrentView.Apply()
            Finally
                Marshal.ReleaseComObject(CurrentView)
            End Try
        End If
    End If
End If

© www.soinside.com 2019 - 2024. All rights reserved.