Print question - Calling Dave Peterson!

G

Guest

I saw this handy code on Ron Debruin's page which prints all hidden and
unhidden pages.

'Dave Peterson
Dim curVis As Long
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
With sh
curVis = .Visible
.Visible = xlSheetVisible
.PrintOut
.Visible = curVis
End With
Next sh
End Sub

Is it possible to incoporate some additional code which excludes some
sheets. Basically I have a report and I want to print all the pages (some
hidden) except the large data dump sheet. Lets say the sheet is called 'Data'.

Is this possible?
 
C

Chip Pearson

Try something like the following:

Dim curVis As Long
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
With sh
Select Case sh.Name
Case "Data1", "Data2", "Data3"
' ignore these sheets
Case Else
curVis = .Visible
.Visible = xlSheetVisible
.PrintOut
.Visible = curVis
End Select
End With
Next sh


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
D

Dave Peterson

And if you wanted to always ignore the sheets that start with data:

Dim curVis As Long
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
With sh
if left(lcase(sh.name),3) <> "data" then
curVis = .Visible
.Visible = xlSheetVisible
.PrintOut
.Visible = curVis
end if
End With
Next sh
End Sub
 
D

David McRitchie

correction for a typo, since the length of "data" is four, the test should be
if left(lcase(sh.name),4) <> "data" then
 
G

Guest

One more question guys...

I would like the report to print out the pages in order. Currently they come
out (I guess) in the order that they are hidden. ie, the code below unhides
each sheet and prints it off so it comes out in that order. I have page
numbers on the footer and would ideally like them to print out in the
numerical order. Problem though is other people use this report, that allows
them to unhide and hide sheets at will, so this will always jumble up the
order.
 
D

Dave Peterson

You could unhide the sheets, put them in numerical order, then hide them again.

If you have a lot of worksheets to put in order, then you may want to look at
Chip Pearson's site:
http://www.cpearson.com/excel/sortws.htm

Remember to name your sheets nicely:

Data001
Data002
....
Data999

If you name them
Data1
Data2
....
Data10
Data11

You'll have trouble getting the sort to work the way you want.
 

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