View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default Prevent printing of certain sheets

"GS" wrote in message
Thanks Garry, but the _BeforePrint event executes in full before printing,
so if I unhide the sheets, the sheets will print.


You're not getting it!...

'hide not to print sheets
'call procedure to print
'_BeforePrint is NOT where to hide not to print sheets
'unhide not to print sheets

Your reply suggests you are doing everything in one procedure. BAD
IDEA!(IMO) but still doable if you hide/print/unhide so _BeforePrint isn't
even in the picture!


Hi Garry,

Hi Peter...

The OP's question is a little ambiguous. It could be interpreted as you did
if the objective were in his own routine to exclude some sheet(s) from being
printed. Indeed something along the lines you suggest would be good, and as
you say the BeforePrint doesn't come into it.

However probably no need to hide any sheets, in the print procedure simply
Worksheets(ArrayOfSheetsToPrint).PrintOut
(the array could be populated in current sheet order if/as appropriate)


This is the way I do it, but felt it's a bit over complicated to introduce
here.

vShtsToPrint = Split(sShtsToPrint, ",")
Worksheets(vShtsToPrint).PrintOut

I interpreted the problem being about if the user clicks Print from the
Ribbon or does Ctrl-P. BeforePrint will fire but then no control over what
the user might attempt to print. Maybe the user might be allowed to print
anything except specified sheets. For that scenario hiding sheets in the
BeforePrint and re-showing in an OnTime would be one way to handle it. Though
would need rather more that I showed in the way of error handling and to
ensure the sheets get re-shown in some other way if the OnTime failed for any
reason.


Yes, I got the same suspicion as to what the OP was doing. The OnTime approach
is a good idea in the _BeforePrint event, but I still feel it shouldn't be done
that way. Using _BeforePrint for evaluating conditionals related to the
printing itself wherein Cancel is set true accordingly is more appropriate.

IMO, if the project is that complex then it ought to have its own dedicated
procedures designed specifically for its tasks!

Of course nothing to stop the user taking a screenshot and printing it!

Peter T


--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion