PropertyTests 集合对象

         
FileSearch
PropertyTests (PropertyTest)
FoundFiles

代表一个文件搜索条件。搜索条件列在“查找”对话框中(单击“文件”菜单中的“打开”命令,然后单击“查找”按钮)。PropertyTest 对象是 PropertyTests 集合中的成员。

使用 PropertyTest 对象

PropertyTests 属性可返回一个 PropertyTests 对象。以下示例显示查找单个文件的“查找”的搜索条件数。

Application.FileSearch.PropertyTests.Count

Add 方法向 PropertyTests 集合中添加一个新的 PropertyTest 对象。以下示例向搜索条件中添加两个属性测试。第一个条件指定查找任意类型的文件,第二个条件指定该文件应是在 1996 年 1 月 1 日至 1996 年 6 月 30 日之间修改的。然后,在消息框中显示找到的文件数和每个文件的名称。

Set fs = Application.FileSearch
fs.NewSearch
 With fs.PropertyTests
    .Add Name:="Files of Type", _
        Condition:=msoConditionFileTypeAllFiles, _
        Connector:=msoConnectorOr
    .Add Name:="Last Modified", _
        Condition:=msoConditionAnytimeBetween, _
        Value:="1/1/96", SecondValue:="6/1/96", _
        Connector:=msoConnectorAnd
 End With
    If fs.Execute() > 0 Then
        MsgBox "There were " & fs.FoundFiles.Count & _
            " file(s) found."
        For i = 1 To fs.FoundFiles.Count
            MsgBox fs.FoundFiles(i)
        Next i
    Else
        MsgBox "There were no files found."
    End If

PropertyTests(index) 可返回一个 PropertyTest 对象;此处 index 是该对象的索引号。以下示例显示 PropertyTests 集合中第一个属性测试的所有搜索条件。

With Application.FileSearch.PropertyTests(1)
myString = "This is the search criteria: " _
    & " The name is: " & .Name & ". The condition is: " _
    & .Condition
If .Value <> "" Then
    myString = myString & ". The value is: " & .Value
    If .SecondValue <> "" Then
        myString = myString _
            & ". The second value is: " _
            & .SecondValue & ", and the connector is" _
            & .Connector
    End If
End If
MsgBox myString
End With