excel 2003 code not working in 2007

stickboy2006

New Member
Joined
Nov 28, 2006
Messages
16
Hi all,

i have some code that ive used for years in 2003, and now, following upgrade to excel 2007, i get a run time error 445 - object doesnt support this action.

this simply searches a location for excel files - and creates a list.


CODE@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Sub test()



Dim fs As Object
Application.ScreenUpdating = False
sourcedir = "c:\"
Set fs = Application.FileSearch
With fs
.LookIn = sourcedir
.filename = "*.xls"
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Sheets("front").Range("a" & (Sheets("front").Range("a65536").End(xlUp).Row + 1)) = .FoundFiles(i)
Next i
Else
Application.Goto Sheets("front").Range("a1"), True
Application.ScreenUpdating = True
MsgBox "There were no files found."
Exit Sub
End If
End With
End Sub

CODE END@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@





Does anyone have a method for this in 2007?

I tried adding old objects in the references in VBA, but it only allows me Objects 12.
I would prefer not to have to go down the route of adding previous references to old excel versions if possible.


many thanks in advance.
Stuart
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
many thanks,


I also found this - much simpler, prob not as consistent.

Sub Showfiles()

Dim fs, SEARCHAREA, ITEM, RESULTS
Set fs = CreateObject("Scripting.fileSystemObject")
Set SEARCHAREA = fs.Getfolder("c:\test")
Set RESULTS = SEARCHAREA.Files

For Each ITEM In RESULTS
Range("a" & Range("a5000").End(xlUp).Row + 1).Value = ITEM.Name
Next

End Sub

many thanks
Stuart
 
Upvote 0
That won't search through subfolders of course, so depending on your actual needs it may not be enough.

A giant pain in the backside their doing away with application.filesearch.

Compatibility issues aside, in many cases it takes an entire module of code with the FileSystemObject to achieve the same results as it took in a few lines.
 
Upvote 0
That won't search through subfolders of course, so depending on your actual needs it may not be enough.

A giant pain in the backside their doing away with application.filesearch.

Compatibility issues aside, in many cases it takes an entire module of code with the FileSystemObject to achieve the same results as it took in a few lines.

Anyone know why they binned application.filesearch?

Also, does DIR still work in '07?
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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