Application.FileSearch error

kmiles

Board Regular
Joined
Apr 1, 2002
Messages
113
The following code works fine in Excel 2003 but returns the following error in Excel 2007:

Run time error '445'
Object does not support this action


CODE:
Sub List_Files()

Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook

Set wbCodeBook = ThisWorkbook

With Application.FileSearch
.NewSearch
.LookIn = "C:\Departments\Inventory\"
.FileType = msoFileTypeAllFiles
.Filename = "20*"
If .Execute > 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through all.
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
Application.StatusBar = Str(lCount) & " files found - Now working on " & ActiveWorkbook.FullName
rteval = MsgBox("Now working on " & ActiveWorkbook.FullName)

wbResults.Close SaveChanges:=True

Next lCount
End If
End With
End Sub
 
Jon

Of course you can use Dir recursively to search subdirectories and as
far as I know you need to use recursion for subdirectories with FSO too.

With FileSearch all you needed to do was set the SearchSubFolders property to true.

I can't see any methods/properties of the FSO that allow text in a file to be searched, though
there are obviously various other useful methods it has that FileSearch doesn't offer.
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
the code posted by kmiles works just fine, but for some reason it is not capturing the very first file in the folder. I messed with it for a while and gave up (with a workaround of course) I put a fake file in the folder that showed up alphabetically first.
 
Upvote 0

Forum statistics

Threads
1,216,499
Messages
6,131,010
Members
449,613
Latest member
MedDash99

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top