下面的代码居然不能运行!红色的行过不去,提示对象不支持该动作!请各位帮忙测试!
Sub SearchEveryFolder()
'Declare variables that reference a
'SearchScope and a ScopeFolder object.
Dim ss As SearchScope
Dim sf As ScopeFolder
'Declare a variable to act as a generic counter.
Dim lngCount As Long
'Use a With...End With block to reference the
'FileSearch object.
With Application.FileSearch
'Clear all the parameters of the previous searches.
'This method doesn't clear the LookIn property or
'the SearchFolders collection.
.NewSearch
'Specify the type of file for which to search.
'Use the FileType property to specify the first type
'and then add additional types to the FileTypes collection.
.FileType = msoFileTypeWebPages
.FileTypes.Add msoFileTypeExcelWorkbooks
'Clear the SearchFolder collection by
'looping through each ScopeFolder object
'and removing it.
For lngCount = 1 To .SearchFolders.Count
.SearchFolders.Remove lngCount
Next lngCount
'Loop through the SearchScopes collection to find
'the scope in which you want to search. In this
'case the scope is the local machine.
For Each ss In .SearchScopes
Select Case ss.Type
Case msoSearchInMyComputer
'Loop through each ScopeFolder in
'the ScopeFolders collection of the
'SearchScope object.
For Each sf In ss.ScopeFolder.ScopeFolders
'Call a function that loops through all
'of the subfolders of the root ScopeFolder.
'This function adds any folders named "1033" to the
'SearchFolders collection.
Call OutputPaths(sf.ScopeFolders, "1033")
Next sf
Case Else
End Select
Next ss
'Test to see if any ScopeFolders collections were added to
'the SearchFolders collection.
If .SearchFolders.Count > 0 Then
'Set the LookIn property to the path of
'the first ScopeFolder object in the SearchFolders
'collection. This is here so that any previous
'setting of the LookIn property doesn't affect
'the search.
.LookIn = .SearchFolders.Item(1).Path
'Execute the search and test to see if any files
'were found.
If .Execute > 0 Then
'Display the number of files found.
MsgBox "Files found: " & .FoundFiles.Count
'Loop through the list of found files and
'display the path of each one in a message box.
For lngCount = 1 To .FoundFiles.Count
If MsgBox(.FoundFiles.Item(lngCount), vbOKCancel, _
"Found files") = vbCancel Then
'Break out of the loop
lngCount = .FoundFiles.Count
End If
Next lngCount
End If
End If
End With
End Sub
[此贴子已经被作者于2006-11-27 21:55:26编辑过]
|