ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   FileSearch Problem (https://www.excelbanter.com/excel-programming/283763-filesearch-problem.html)

Jarek[_3_]

FileSearch Problem
 

Hello,
I'm trying to use Application.FileSearch method to find files in
given directory, using '*' as wildcard. But the macro below stops a
line .FileName="*.xls" (error '5' - invalid parameter)
I've tried to find different types of files, but some extensions i
.FileName allways causes error (*.xls, *.xla, *.rar, *.zip), som
extensions sometimes (*.dbf, *.txt), some extensions are OK (*.doc
*.pps).
What am I doing wrong?
W'2000, XL'97

Sorry for my English.
Many thanks
Jarek

Sub ListFiles()
With Application.FileSearch
.NewSearch
.LookIn = "C:\Data\Excel"
.SearchSubFolders = False
.FileName = "*.xls"
.Execute
End With

cnt = Application.FileSearch.FoundFiles.Count
For i = 1 To cnt
MsgBox Application.FileSearch.FoundFiles.Item(i)
Next i
End Su

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com


Ron de Bruin

FileSearch Problem
 
Try it without the * like .xls

If this not work use the Dir function
See the VBA help for more information

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Jarek" wrote in message ...

Hello,
I'm trying to use Application.FileSearch method to find files in a
given directory, using '*' as wildcard. But the macro below stops at
line .FileName="*.xls" (error '5' - invalid parameter)
I've tried to find different types of files, but some extensions in
FileName allways causes error (*.xls, *.xla, *.rar, *.zip), some
extensions sometimes (*.dbf, *.txt), some extensions are OK (*.doc,
*.pps).
What am I doing wrong?
W'2000, XL'97

Sorry for my English.
Many thanks
Jarek

Sub ListFiles()
With Application.FileSearch
NewSearch
LookIn = "C:\Data\Excel"
SearchSubFolders = False
FileName = "*.xls"
Execute
End With

cnt = Application.FileSearch.FoundFiles.Count
For i = 1 To cnt
MsgBox Application.FileSearch.FoundFiles.Item(i)
Next i
End Sub


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/




Don Guillett[_4_]

FileSearch Problem
 
You didn't mention xl version but try without the *

.Filename = ".xls"

--
Don Guillett
SalesAid Software

"Jarek" wrote in message
...

Hello,
I'm trying to use Application.FileSearch method to find files in a
given directory, using '*' as wildcard. But the macro below stops at
line .FileName="*.xls" (error '5' - invalid parameter)
I've tried to find different types of files, but some extensions in
FileName allways causes error (*.xls, *.xla, *.rar, *.zip), some
extensions sometimes (*.dbf, *.txt), some extensions are OK (*.doc,
*.pps).
What am I doing wrong?
W'2000, XL'97

Sorry for my English.
Many thanks
Jarek

Sub ListFiles()
With Application.FileSearch
NewSearch
LookIn = "C:\Data\Excel"
SearchSubFolders = False
FileName = "*.xls"
Execute
End With

cnt = Application.FileSearch.FoundFiles.Count
For i = 1 To cnt
MsgBox Application.FileSearch.FoundFiles.Item(i)
Next i
End Sub


------------------------------------------------
~~ Message posted from
http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/




Jarek[_4_]

FileSearch Problem
 

Thank you, Ron,
it works great.
Jare

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com



All times are GMT +1. The time now is 05:17 AM.

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