目录

NewSearch 方法

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

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

将所有搜索条件重置为默认设置。

expression.NewSearch

expression 必需。该表达式返回一个FileSearch 对象。

说明

搜索条件的设置在应用程序的一个会话中将保持不变。每次更改搜索条件时可用此方法。此方法不会重新设置LookIn 属性的值。

示例

本示例可实现的功能为:在开始新一轮搜索过程之前用NewSearch 方法重新设置默认的搜索条件。

With Application.FileSearch
 .NewSearch
 .LookIn = "C:\My Documents"
 .SearchSubFolders = True
 .FileName = "run"
 .TextOrProperty = "San*"
 .MatchAllWordForms = True
 .FileType = msoFileTypeAllFiles
 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