RefreshScopes 方法

       

刷新当前可用 ScopeFolder 对象的列表。

expression.RefreshScopes

expression   必需。该表达式返回“应用于”列表中的对象之一。

示例

本示例显示“我的电脑”范围内 C:\ 驱动器上所有当前可用的 ScopeFolder 对象。

Sub TestRefreshScopesMethod()
' Displays what happens before and after the RefreshScopes
' method is called when a new folder is added to the list
' of scope folders.

    ' List before the folder is created.
    Call ListFolderNames
    
    ' Create a new folder on the C:\ drive in My Computer.
    ' An error will occur if this folder already exists.
    MkDir Path:="C:\Delete_After_Using"
    
    ' List after the folder is created.
    Call ListFolderNames
    
    ' Refresh the list of folders.
    Application.FileSearch.RefreshScopes
    
    ' The newly-created folder now appears in the list.
    Call ListFolderNames
    
End Sub

Sub ListFolderNames()

    Dim strResults As String
    
    ' Loop through all the folder names on the C:\ drive
    ' in My Computer and report the results.
    ' .SearchScopes.Item(1) = "My Computer"
    ' .ScopeFolders.Item(2) = "C:\"
    With Application.FileSearch.SearchScopes.Item(1). _
        ScopeFolder.ScopeFolders.Item(2)
        
        For i = 1 To .ScopeFolders.Count
            strResults = strResults & .ScopeFolders. _
                Item(i).Name & vbCrLf
        Next i
        
        MsgBox "Folder Names on C:\...." & vbCrLf & strResults
    
    End With
    
End Sub