View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
kjs[_2_] kjs[_2_] is offline
external usenet poster
 
Posts: 2
Default FileSearch behaviour

FileSearch is producing duplicate results - listing the same file twice in
the FileSearch object. Additionally it's listing files outside the specified
"C:\" drive. Some are found in the E drive, which is a flash stick. Even
when this stick has been pulled out. Even when it's been pulled out
and the computer restarted! I guess the search results are stored
somewhere, but am clueless about the duplicates.

Kevin.

The code used:

Public Sub SearchForXLsheets()

Dim oFound As FileSearch
Dim l As Long

Set oFound = Application.FileSearch
With oFound
.NewSearch
.LookIn = "C:\"
.SearchSubFolders = True
.FileType = msoFileTypeExcelWorkbooks
.Execute SortBy:=msoSortByFileName
If .FoundFiles.Count 0 Then
For l = 1 To .FoundFiles.Count
Cells(l, 1).Value = .FoundFiles(l)
Next l
End If
Columns("A:A").EntireColumn.AutoFit
End With
Set oFound = Nothing

End Sub