Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making an Excel tab not print?

Tags:

excel

Is there any way in Excel to make it so that a particular tab isn't included when you print the entire workbook? As in, Sheet1, Sheet2, and Sheet3 print, but not Sheet4.

So like when someone goes to File -> Print or whatever, and hit OK, etc, everything prints out except for a particular designated tab (which I assume I have to "hide from printing" somehow).

I'm sending this workout out to a bunch of people so I'm trying to avoid forcing them to enable/run macros and all that stuff. Is there just a property of a sheet somewhere like "exclude from print"?

like image 330
MyNameIsKhan Avatar asked Nov 08 '13 16:11

MyNameIsKhan


3 Answers

These answers will require the use of macros.
Hide the sheet before printing.

 sheets("WorksheetToNotPrint").visible = xlSheetHidden 'or 0

or

 sheets("WorksheetToNotPrint").visible = xlSheetVeryHidden 'or 2
 'used if you don't want people to unhide the worksheet without knowing code

and

 sheets("WorksheetToNotPrint").visible = xlSheetVisible 'or -1

when done

another option is to print the sheets you want printed (may be useful if you only want a few sheets printed:

Sub Print_Specific_Sheets()
Sheets(Array("Sheet1", "Sheet2", "Sheet4")).Select
ActiveWindow.SelectedSheets.PrintOut
Sheets("Sheet1").Select
End Sub
like image 73
SeanC Avatar answered Oct 06 '22 15:10

SeanC


Actually the answer seems to be surprisingly simple.

If you hide the sheet, it will not be printed when you print the entire workbook.

You won't need a macro, just

  1. right click on the sheet name
  2. choose hide

If needed you or other users can unhide it as well.

like image 34
Dennis Jaheruddin Avatar answered Oct 06 '22 17:10

Dennis Jaheruddin


If you use the BeforePrint event then you can alter what the built in print function can do. The BeforePrint macro is inside 'ThisWorkbook' under 'Workbook'.

For example you can hide sheet 4 so it doesn't print like this:

Private Sub aWorkbook_BeforePrint(Cancel As Boolean)
    Sheets(4).Visible = xlSheetHidden
End Sub

The downside to this method is there is no AfterPrint method to unhide the sheets. So you need to circumvent the print dialog. There are several ways to do this but here is one very simplistic method. (Note: This might not be a good solution if you have many other printing scenarios that you need to account for)

Here I am telling exactly what sheets to print (only sheet 1 and 4). You can use names instead of numbers and you can even create a loop and look for variables to determine what sheets you want to print.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Application.EnableEvents = False

    Sheets(Array("1", "4")).PrintOut , , 1

    Application.EnableEvents = True

    '//prevent the default print
    Cancel = True
End Sub
like image 28
Automate This Avatar answered Oct 06 '22 17:10

Automate This