Find Files

B

Bill

Hello,
I am using the following code to find a file on the C drive. The file is
there, but the code keeps saying no file was found. Any help? Thanks.

Sub test()

Set fs = Application.FileSearch
With fs
.LookIn = "C"
.Filename = "Fname.xls"
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
 
W

William

Bill

Try inserting the following line after the ".LookIn" line in your code..

..-------
..SearchSubFolders = True
-------
--


XL2003
Regards

William
(e-mail address removed)
 
J

Jim Cone

Bill,

Your code worked for me when I declared the two variables
and corrected the directory designation...
'-----------------
Dim fs
Dim i As Long
Set fs = Application.FileSearch
With fs
.LookIn = "C:\"
'---------------------

Jim Cone
San Francisco, USA


Hello,
I am using the following code to find a file on the C drive. The file is
there, but the code keeps saying no file was found. Any help? Thanks.

Sub test()
Set fs = Application.FileSearch
With fs
.LookIn = "C"
.Filename = "Fname.xls"
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
 
W

William

Bill

Replace ".LookIn = "C" with ".LookIn = "C:"

--


XL2003
Regards

William
(e-mail address removed)
 

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