Print all Sheet2 of all Workbooks in Folder
Filesearch will not work with excel 2007. You should also make sure there
are at leastt 2 sheets in the workbook before you try to print. also you
left off WB from the Printout statement.
Sub PrintAllWS2()
Dim i As Long
Dim WB As Workbook
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.LookIn = "F:\VBA845\"
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
For i = 1 To .FoundFiles.Count
Set WB = Workbooks.Open(.FoundFiles(i))
if WB.Sheets.Count = 2 then
WB.Sheets("Sheet2").PrintOut
end if
WB.Close False
Next i
End With
Application.ScreenUpdating = True
End Sub
"u473" wrote:
This little module crashes on "With Application.FileSearch".
That may not be the real culprit, but I have not found what is wrong.
Thank you for your help.
..
Sub PrintAllWS2()
Dim i As Long
Dim WB As Workbook
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.LookIn = "F:\VBA845\"
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
For i = 1 To .FoundFiles.Count
Set WB = Workbooks.Open(.FoundFiles(i))
Sheets("Sheet2").PrintOut
WB.Close False
Next i
End With
Application.ScreenUpdating = True
End Sub
|