LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default Cancel printing a worksheet

Having a similar problem where I never wanted a selected sheet to
print. The solutions posted at best still printed something when the
sheet that I did not want to print was active. I used the following
code to alway block the printing of "Sheet1" in the example where the
workbook has three (3) sheets:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Sheet1" Then
MsgBox "Print Error, Unable to Print Sheet1", vbCritical
Cancel = True
Else
If ActiveSheet.Name = "Sheet2" Or ActiveSheet.Name = "Sheet3" Then
Application.DisplayAlerts = False
Application.EnableEvents = False
ThisWorkbook.Worksheets("Sheet1").Visible = xlVeryHidden
Application.Dialogs(xlDialogPrint).Show
ThisWorkbook.Worksheets("Sheet1").Visible = xlSheetVisible
Application.DisplayAlerts = True
Application.EnableEvents = True
Cancel = True
End If
End If
End Sub

The down side of this solution is that one must list all other
workbook sheets in the line following the "Else" statement. The
"Cancel" command near the end of the code was necessary to prevent two
(2) sheets from printing.
 
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
Workbook_BeforeClose(Cancel As Boolean) - Cancel won't work gpmichal Setting up and Configuration of Excel 1 May 12th 09 02:33 AM
printing a worksheet Jim Excel Discussion (Misc queries) 2 January 4th 09 06:57 PM
Printing worksheet Robyn M New Users to Excel 3 December 11th 08 08:37 PM
Worksheet printing Laura Excel Worksheet Functions 2 April 19th 07 05:40 PM
printing worksheet Ruster2 Excel Discussion (Misc queries) 1 June 22nd 06 09:41 PM


All times are GMT +1. The time now is 08:13 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"