Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Print multiple worksheets

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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Print multiple worksheets

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

--
Regards,
Tom Ogilvy


"Howard Packham" wrote in message
...
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!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Print Multiple worksheets Ted Excel Worksheet Functions 2 November 4th 09 04:28 PM
How do I print a spreadsheet with multiple worksheets? Need Help Excel Discussion (Misc queries) 1 May 23rd 06 10:17 PM
How do I print multiple worksheets on one page? renonv Excel Discussion (Misc queries) 1 December 17th 05 03:42 PM
print multiple worksheets on one page Michelle Excel Discussion (Misc queries) 2 November 21st 05 06:25 PM
What is the simplest way to print multiple worksheets? substring Charts and Charting in Excel 1 April 21st 05 11:49 PM


All times are GMT +1. The time now is 09:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"