FileSearch 对象

         
FileSearch
多个对象

本主题中的某些内容可能不适用于某些语言。

代表“文件”菜单中“打开”对话框的功能。

使用 FileSearch 对象

FileSearch 属性可返回 FileSearch 对象。以下示例可实现:查找指定文件并显示找到的文件数及每个找到的文件的标题。

With Application.FileSearch
    If .Execute() > 0 Then
        MsgBox "There were " & .FoundFiles.Count & _
            " file(s) found."
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
        MsgBox "There were no files found."
    End If
End With

NewSearch 方法可将搜索条件重新设置为默认设置。所有属性值在每次搜索过程后仍然保持不变,用 NewSearch 方法可有选择地为下一次文件搜索过程设置属性,而无须手动重新设置原先的属性值。以下示例可实现:在开始新的一轮搜索之前将搜索条件重新设置为默认设置。

With Application.FileSearch
    .NewSearch
    .LookIn = "C:\My Documents"
    .SearchSubFolders = True
    .FileName = "Run"
    .MatchTextExactly = True
    .FileType = msoFileTypeAllFiles
End With