ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find Files (https://www.excelbanter.com/excel-programming/339050-find-files.html)

Bill[_30_]

Find Files
 
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



William[_2_]

Find Files
 
Bill

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

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


XL2003
Regards

William



"Bill" wrote in message
ink.net...
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





Bill[_30_]

Find Files
 
Thanks for your suggestion. Unfortunately that did not work.


"William" wrote in message
...
Bill

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

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


XL2003
Regards

William



"Bill" wrote in message
ink.net...
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







Jim Cone

Find Files
 
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


"Bill" wrote in message
ink.net...
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



William[_2_]

Find Files
 
Bill

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

--


XL2003
Regards

William



"Bill" wrote in message
ink.net...
Thanks for your suggestion. Unfortunately that did not work.


"William" wrote in message
...
Bill

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

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


XL2003
Regards

William



"Bill" wrote in message
ink.net...
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









Bill[_30_]

Find Files
 
Thanks. That worked.


"Jim Cone" wrote in message
...
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


"Bill" wrote in message
ink.net...
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






All times are GMT +1. The time now is 10:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com