Print multiple worksheets

H

Howard Packham

Hello,
I've got button in an excel worksheet which triggers code to print out
all the other excel files in that same folder. Most of it works ok, but
it fails when it trys to open the current file (which, of course, if
already open). This is the code so far...

Sub PrintAllReport()
DirName = ThisWorkbook.Path & "\"
Nextbook = Dir(DirName & "*.xls")
Do While Nextbook <> ""
Sheets("Mth title").Select
ActiveWindow.SelectedSheets.PrintOut
ActiveWorkbook.Save
ActiveWorkbook.Close
Nextbook = Dir()
Loop
MsgBox "Done"
End Sub

At what point (and how) should I write the code to skip over the current
file?

Any help would be greatly appreciated.

Thanks.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
T

Tom Ogilvy

Sub PrintAllReport()
DirName = ThisWorkbook.Path & "\"
Nextbook = Dir(DirName & "*.xls")
Do While Nextbook <> ""
bThisBook = False
if Ucase(NextBook) <> Ucase(ThisWorkbook.Name) then
workbooks.Open ThisWorkbook.Path & "\" & NextBook
bThisBook = True
End if
Sheets("Mth title").Select
ActiveWindow.SelectedSheets.PrintOut
ActiveWorkbook.Save
If Not bThisBook then ActiveWorkbook.Close
Nextbook = Dir()
Loop
MsgBox "Done"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top