View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_7_] Peter T[_7_] is offline
external usenet poster
 
Posts: 162
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,

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)

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.

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

Peter T