Help with Application.FileSearch method

R

Roy Harrill

I copied the code below right out of Excel VBA Help, changing only the
folder specified in ".Lookin" to "C:\Tsfr". I know this folder exists on my
computer and contains three .doc files. Therefore the code should report
three files found, but instead it erroneously reports no files found. Any
suggestions as to what's going on would be appreciated. Thanks.

Sub Filetest()
Set fs = Application.FileSearch
With fs
.LookIn = "C:\Tsfr"
.Filename = "*.doc"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For Counter = 1 To .FoundFiles.Count
MsgBox .FoundFiles(Counter)
Next Counter
Else
MsgBox "There were no files found."
End If
End With
End Sub
 
R

Roy Harrill

Ron,
Thanks for the reply. I tried that, but unfortunately got the same result.
BTW, I'm running Windows XP Pro SP2 and Excel 2003.
Roy
 
R

Roy Harrill

Thanks again, Ron. I changed to using a Dir approach and everything works
fine. Looks like ole MS needs to do a little work on FileSearch. Do I look
surprised?
Roy

Hi Roy

There are more problems with FileSearch.
Use Dir instead or fill a array with file names

Maybe you can steal some code from this page.
http://www.rondebruin.nl/copy3.htm

--
Regards Ron de Bruin
http://www.rondebruin.nl

Ron,
Thanks for the reply. I tried that, but unfortunately got the same result.
BTW, I'm running Windows XP Pro SP2 and Excel 2003.
Roy

Hi roy

Try it with:
.LookIn = "C:\Tsfr\"
.Filename = ".doc"

--
Regards Ron de Bruin
http://www.rondebruin.nl

I copied the code below right out of Excel VBA Help, changing only the
folder specified in ".Lookin" to "C:\Tsfr". I know this folder exists on my
computer and contains three .doc files. Therefore the code should report
three files found, but instead it erroneously reports no files found. Any
suggestions as to what's going on would be appreciated. Thanks.

Sub Filetest()
Set fs = Application.FileSearch
With fs
.LookIn = "C:\Tsfr"
.Filename = "*.doc"
If .Execute(SortBy:=msoSortByFileName,
SortOrder:=msoSortOrderAscending) > 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
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top