Printing Selection

Ody

Board Regular
Joined
Oct 14, 2010
Messages
215
Hello,

I'm having trouble creating a printing macro that will print all the hidden sheets in my workbook except for 2 (sheet2 and sheet3). Thus far all my attempts have been in vane.

I appreciate any help!

Thanks!!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
It's helpful to post what you've got already, to give us a flavour of the environment you're working in, and also to show you've actually tried to make a solution before asking for one.

This will also help to prevent posters coming back after a solution is offered, and saying it needs changing, because they didn't specify EXACTLY what they actually wanted in the first place.

However, this will do as you've specified. You could either call it from any other procedure (in it's own right:
Code:
 Sub print_hidden_sheets()
Dim ws As Worksheet
Application.ScreenUpdating = False
  On Error Resume Next
    For Each ws In ThisWorkbook.Sheets

        If ws.Visible = xlSheetHidden And ws.Name <> "Sheet2" And ws.Name <> "Sheet3" Then
          
            ws.Visible = xlSheetVisible
            ws.PrintOut
            ws.Visible = xlSheetHidden
            
         End If
    Next
Application.ScreenUpdating = True
End Sub
, or better still, place it in the _click event of a command button on a sheet:
Code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Application.ScreenUpdating = False
  On Error Resume Next
    For Each ws In ThisWorkbook.Sheets

        If ws.Visible = xlSheetHidden And ws.Name <> "Sheet2" And ws.Name <> "Sheet3" Then
          
            ws.Visible = xlSheetVisible
            ws.PrintOut
            ws.Visible = xlSheetHidden
            
         End If
    Next
Application.ScreenUpdating = True
End Sub

....you may wish to specify the number of pages etc, and this can be done by adjusting the arguments after the "Printout" statement.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top