VBA Outlook - 读取当前资源管理器搜索过滤器

VBA Outlook - read the current explorer search filter

我想读取 Explorer.Search 函数的当前过滤器。
我用这段代码试过了:

private sub read_old_filter()
    dim objExplorer as Outlook.Explorer
    dim oldFiler as String

    set objExplorer = Outlook.ActiveExplorer
    oldFilter = objExplorer.search
end sub

但是objExplorer.search是一个函数,所以它不能工作。

我想重复使用旧过滤器。我有 makros 如何过滤 strFilter = "received:(today OR yesterday)" 之类的东西。 private sub read_old_filter() 在我的用户表单中。我想连接用户窗体的旧过滤器和新过滤器。

谁能帮帮我?
感谢您的任何表扬和回答。亲切的问候,妮可

这在 Outlook VBA 中显然直接 不可能。虽然有一个 ActiveExplorer.CurrentView.Filter 以及一个 XML 属性 的视图,但这不会暴露当前的过滤器 query/condition.

但是在搜索时我遇到了这个线程,它提到了 Redemption,它似乎提供了你需要的东西: How to get a search folder criteria in Outlook

希望对您有所帮助。

我有个好主意。我创造了我的 Modul1 全球价值观。在这个值中是宏的过滤器选项。 我用 Integer 保存当前过滤器编号。 Public Function 读取 Integer 并使用 Select Case 将正确的过滤器传递给用户表单。

模块 1

Const FILTER_1 As String = ""                               'löscht alle filter
Const FILTER_2 As String = "followupflag:(followup flag)"   'zeigt nur Tasks an
Const FILTER_3 As String = "received:(today OR yesterday)"  'zeigt nur mails von heute und gestern
Dim filterUsed As Integer

'select right filter and save the number
Sub ViewFilter_all()
    filterUsed = 1
    Call filter_aktualisieren(FILTER_1)
End Sub
Sub onlyTasks()
    filterUsed = 2
    Call filter_aktualisieren(FILTER_2)
End Sub
Sub ViewFilter_today()
    filterUsed = 3
    Call filter_aktualisieren(FILTER_3)
End Sub
'search function for the macros
Private Sub filter_aktualisieren(strFilter As String)
    Dim objExplorer As Object
    Set objExplorer = Outlook.ActiveExplorer

    objExplorer.search strFilter, Outlook.OlSearchScope.olSearchScopeCurrentFolder
    objExplorer.Display
End Sub
'function to pass the filter to the userform
Public Function getFilterUsed() As String
    Select Case filterUsed
        Case 1
            getFilterUsed = FILTER_1
        Case 2
            getFilterUsed = FILTER_2
        Case 3
            getFilterUsed = FILTER_3
        Case Else
            getFilterUsed = "none"
    End Select
End Function

部分用户表单

Public Sub UserForm_Initialize()
    'code....
    'vorFilter is a Global String in my Userform
    vorFilter = getFilterUsed()
    'code....
End Sub

希望解决方案也能帮助其他人。