Excel 2007 code for file directory loop - can't use Application.Filesearch

seagreen

Board Regular
Joined
Feb 7, 2009
Messages
71
Hello,
I have been trying to process Excel files in a directory with the following code:
Code:
Sub FindExcelFiles()
Dim foldername As String
Dim FSO As Object
Dim fldr As Object
Dim file As Object
Dim cnt As Long
    foldername = "c:\users\bseagreen\desktop\TuesdayFeb102009\week ending feb 7 2009\testing2\"
    Set FSO = CreateObject("Scripting.FilesystemObject")
    Set fldr = FSO.GetFolder(foldername)
    For Each file In fldr.Files
        If file.Type Like "*Microsoft Office Excel*" Then
            cnt = cnt + 1
        End If
        Application.StatusBar = "Now working on " & ActiveWorkbook.FullName
        DoSomething ActiveWorkbook
    Next file
    Set file = Nothing
    Set fldr = Nothing
    Set FSO = Nothing
    Range("A1").Value = cnt
End Sub

Here's the stub for the subroutine that's being called:
Code:
Sub DoSomething(inBook As Workbook) 'Massage each workbook
'Debug.Print "Hello"
Debug.Print ActiveWorkbook.FullName
End Sub

I am using Excel 2007. I found out I cannot use Application.Filesearch as Microsoft has dropped this method for 2007. My problem now is that I just see "Now working on c:\users\bseagreen\desktop\TuesdayFeb102009\week ending feb 7 2009\testing2\file1.xls written six times in the immediate window. Can anyone help me figure out why the code isn't looping through all the files. I'm new at VBA and am probabluy missing something obvious.

Thanks in advance for your help.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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