Print macro excluding some hidden sheets

Ody

Board Regular
Joined
Oct 14, 2010
Messages
215
Hello all,

I've been searching the web today looking for a macro that will allow me to print my entire workbook excluding certain hidden sheets (sheet2 and sheet3). I've located macros that print all hidden sheets, macros that exclude certain unhidden sheets, but not the combo I'm looking for. Anyone have any advice on this?

Here's what I'm unsuccessfully working with right now:


Code:
Sub Print_Hidden_And_Visible_Worksheets() 
  Dim CurVis As Long 
  Dim sh As Worksheet 
    
    For Each sh In ActiveWorkbook.Worksheets 
      With sh CurVis = .Visible 
         .Visible = xlSheetVisible 
         .PrintOut 
         .Visible = CurVis End 
      With 
    Next sh 
 
End Sub

Thanks much!
 
Last edited by a moderator:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How's this:

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> foo()<br>    <SPAN style="color:#00007F">Dim</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet<br>        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> ActiveWorkbook.Worksheets<br>            <SPAN style="color:#00007F">If</SPAN> ws.Visible = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN> ws.PrintPreview<br>        <SPAN style="color:#00007F">Next</SPAN> ws<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

Just change PrintPreview to PrintOut if it does what you want.

HTH,
 
Upvote 0
Thanks for the quick reply Smitty!

The code works great, however, the only visible sheet is sheet1. I'd like to print the remaining hidden sheets except for sheet2 and sheet3. Thoughts?
 
Upvote 0

Forum statistics

Threads
1,224,541
Messages
6,179,418
Members
452,912
Latest member
alicemil

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