SearchScope 对象

优质
小牛编辑
130浏览
2023-12-01

对应于可使用 FileSearch 对象搜索的文件夹树的类型。例如,该计算机上的本地驱动器表示一个搜索范围。网络文件夹和 Microsoft Outlook 文件夹也可能是可用的独立搜索范围。每个 SearchScope 对象包含一个 ScopeFolder 对象,对应于搜索范围的根文件夹。

使用 SearchScope 对象

使用 SearchScopes 集合的 Item 方法返回 SearchScope 对象,例如:

Dim ss As SearchScope
Set ss = Application.FileSearch.SearchScopes.Item(1)

最终,SearchScope 对象要提供对可添加到 SearchFolders 集合的 ScopeFolder 对象的访问。有关演示如何实现的示例,请参阅 SearchFolders 集合的主题。

请参阅 ScopeFolder 对象的主题查阅如何从 SearchScope 对象返回 ScopeFolder 对象的简单示例。

本示例显示所有当前可用的 SearchScope 对象。

Sub DisplayAvailableScopes()

    'Declare a variable that references a
    'SearchScope object.
    Dim ss As SearchScope

    'Use a With...End With block to reference the
    'FileSearch object.
    With Application.FileSearch

        'Loop through the SearchScopes collection.
        For Each ss In .SearchScopes
            Select Case ss.Type
                Case msoSearchInMyComputer
                    MsgBox "My Computer is an available search scope."
                Case msoSearchInMyNetworkPlaces
                    MsgBox "My Network Places is an available search scope."
                Case msoSearchInOutlook
                    MsgBox "Outlook is an available search scope."
                Case msoSearchInCustom
                    MsgBox "A custom search scope is available."
                Case Else
                    MsgBox "Can't determine search scope."
            End Select
        Next ss
    End With
End Sub
SearchScopes
SearchScope
ScopeFolder