ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel 2007 / application.filesearch no longer works (https://www.excelbanter.com/excel-programming/417084-excel-2007-application-filesearch-no-longer-works.html)

Pete Ross

Excel 2007 / application.filesearch no longer works
 
Hello,

In 2007, the application.filesearch no longer works for my vba scripts, I'm
trying to find a work around, I figured out how to loop through files in a
given folder, but need help creating one more nested loop so that I can loop
through folders, then loop through the files in each folder, here is a sample
of what I have so far, any help would be greatly appreciated.

Dim sFolder As String
Dim Folder As Object
Dim file As Object
Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")
sFolder = "C:\temp"
'***I have multiple folders in temp, need to find code to loop thru each......
If sFolder < "" Then
Set Folder = fso.GetFolder(sFolder)
For Each file In Folder.Files
MyFile = file
'**** do stuff to each file
Next file
End If



Ron de Bruin

Excel 2007 / application.filesearch no longer works
 
See
http://www.rondebruin.nl/fso.htm

See also the Merge add-in
http://www.rondebruin.nl/merge.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Pete Ross" wrote in message ...
Hello,

In 2007, the application.filesearch no longer works for my vba scripts, I'm
trying to find a work around, I figured out how to loop through files in a
given folder, but need help creating one more nested loop so that I can loop
through folders, then loop through the files in each folder, here is a sample
of what I have so far, any help would be greatly appreciated.

Dim sFolder As String
Dim Folder As Object
Dim file As Object
Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")
sFolder = "C:\temp"
'***I have multiple folders in temp, need to find code to loop thru each......
If sFolder < "" Then
Set Folder = fso.GetFolder(sFolder)
For Each file In Folder.Files
MyFile = file
'**** do stuff to each file
Next file
End If




All times are GMT +1. The time now is 12:47 PM.

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