ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Print question - Calling Dave Peterson! (https://www.excelbanter.com/excel-discussion-misc-queries/79837-print-question-calling-dave-peterson.html)

Ant

Print question - Calling Dave Peterson!
 
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?

Chip Pearson

Print question - Calling Dave Peterson!
 
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


"Ant" wrote in message
...
Thanks Tom. What would need adding if I actually had three
(maybe more)
sheets I wanted excluded, say 'Data1', 'Data2', Data3'.

"Tom Ogilvy" wrote:

'Dave Peterson
Dim curVis As Long
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
With sh
if lcase(sh.name) < "data" then
curVis = .Visible
.Visible = xlSheetVisible
.PrintOut
.Visible = curVis
end if
End With
Next sh
End Sub

--
Regards,
Tom Ogilvy



"Ant" wrote:

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?




Dave Peterson

Print question - Calling 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

Ant wrote:

Thanks Tom. What would need adding if I actually had three (maybe more)
sheets I wanted excluded, say 'Data1', 'Data2', Data3'.

"Tom Ogilvy" wrote:

'Dave Peterson
Dim curVis As Long
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
With sh
if lcase(sh.name) < "data" then
curVis = .Visible
.Visible = xlSheetVisible
.PrintOut
.Visible = curVis
end if
End With
Next sh
End Sub

--
Regards,
Tom Ogilvy



"Ant" wrote:

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?


--

Dave Peterson

David McRitchie

Print question - Calling Dave Peterson!
 
correction for a typo, since the length of "data" is four, the test should be
if left(lcase(sh.name),4) < "data" then



Dave Peterson

Print question - Calling Dave Peterson!
 
Thanks for the correction....

(If I could count, I'd be dangerous!)

David McRitchie wrote:

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


--

Dave Peterson

Ant

Print question - Calling Dave Peterson!
 
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.


"Dave Peterson" wrote:

Thanks for the correction....

(If I could count, I'd be dangerous!)

David McRitchie wrote:

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


--

Dave Peterson


Dave Peterson

Print question - Calling 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.

Ant wrote:

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.

"Dave Peterson" wrote:

Thanks for the correction....

(If I could count, I'd be dangerous!)

David McRitchie wrote:

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


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 02:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com