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
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
As I just discovered myself, Application.FileSearch was dropped from Office 2007 :confused: :(

Looks like we'll have to use something else to get the job done. Sigh. I'm off to attempt to learn more about the Dir function now, myself...
 
Upvote 0
They dropped FileSearch from Excel 2007? Why?:eek:

As far as I can see that's another reason not to upgrade.

Perhaps using Dir is the answer, but what about the FileSystemObject is the way to go.:)
 
Upvote 0
They dropped FileSearch from Excel 2007? Why?:eek:

From what I saw in my brief searching, it was buggy and they didn't want to bother to fix it, apparently. :confused:

Edit: Removal confirmed by Jon Peltier here:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=450752&SiteID=1

It *is* still shown in examples if you search for it in Help, though. I did a search for "filesearch" in Excel 2007 offline help and the first thing it returns is "filesearch.LookIn Property" with sample code using Application.FileSearch.

It's ridiculous.
 
Upvote 0
They also didn't seem to think it was used all that much, given the more recent introduction of FSO. Never mind that once written, code stays around for a long time.

The online help is more up to date. I just hunted for FileSearch, and got no mention of it at all (not even a helpful note that it had been deprecated and a link to an alternative).
 
Upvote 0
this works

Thanks for the help !

The DIR command works fine.

Sub get_files()
Dim fName

fName = Dir("*.xlsm")
Do While Len(fName) > 0
Debug.Print fName
fName = Dir
Loop

End Sub
 
Upvote 0
They also didn't seem to think it was used all that much, given the more recent introduction of FSO. Never mind that once written, code stays around for a long time.

That's so true Jon: should we ever upgrade here at work, there's a few files that will need to be modified to account for just this change. I wonder how many other VBA mods have been made? I liked the FileSearch - it was quick and simple to use... :(
 
Upvote 0
Richard -

I don't think much else has changed in VBA, aside from glitches. However, I've run into some issues in charting which are more than glitches. In fact they are enough that I just can't upgrade until they're fixed.
 
Upvote 0
I realise FileSearch could be buggy but I certainly used it.:)

Can't quite remember why though.:eek:

But I think it seemed to give more options than Dir(). eg searching subdirectories, searching for text in files
 
Upvote 0
You would use Dir recursively to search subdirectories. I wonder if FSO can find text within files....
 
Upvote 0

Forum statistics

Threads
1,215,500
Messages
6,125,166
Members
449,210
Latest member
grifaz

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