Hello,
I have been trying to process Excel files in a directory with the following code:
Here's the stub for the subroutine that's being called:
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.
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.