Looping Through Workbooks in Folder

millhouse123

Active Member
Joined
Aug 22, 2006
Messages
335
I got this code from Excel help and it doesn't seem to be working and I am not sure why.

I get an erro on Application.FileSearch that "Object doesn't support action"

Any ideas?

Thanks


Code:
With Application.FileSearch
        .NewSearch
        .LookIn = Currentpath
        .FileType = msoFileTypeExcelWorkbooks
        '.Filename = "Book*.xls"
            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)
                 'ActiveWorkbook.Range("D153:D223").Copy
                 'X = X + 2
                 'CodeWB.Worksheet("Scoring Calc").Cells(16, X + 2).Paste
                 'wbResults.Close SaveChanges:=False
                 Next lCount
            End If
    End With
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I am sorry I didn't see the link the first time I looked. In the mean time I had found this link through google. Reguardless the solutions are a little above my skill. I was looking at the solution that added two class modules but I really don't understand how they work. I added two class modules and then replaced the application.fileserach line with New FileSearch but I get some kind of error. I guess I don't know enough about vba yet do figure it out on my own so any help would be awsome.
 
Upvote 0
Thanks for the link, I was wondering how do I add a format? The current format uses .xlsx but I would also like to look for .xls in the same loop.
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,720
Members
449,050
Latest member
MiguekHeka

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