PDA

View Full Version : loop through workbooks



austenr
10-25-2006, 09:26 AM
Can you loop through workbooks, run a macro, print a sheet and go on to the next workbook?

Bob Phillips
10-25-2006, 10:08 AM
Sub LoopFolders()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object

Set oFSO = CreateObject("Scripting.FileSystemObject")

selectFiles "c:\MyTest"

Set Folder = oFSO.GetFolder(sPath)

For Each oFile In oFolder.Files
If oFile.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=oFile.Path
Application.Run "'" & ActiveWorkbook.Name & "'!myMacro"
ActiveWorkbook.Worksheets(1).PrintOut
End If
Next file

Set oFolder = Nothing
Set oFSO = Nothing

End Sub

austenr
10-25-2006, 11:01 AM
Thanks Bob