Print Preview for hidden sheets

Gambit12

New Member
Joined
Mar 31, 2025
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Good morning,
VBA rookie here. Hoping someone can help me with my issue.
I am trying to create a button to have each sheet be listed in the print preview using a button. Each sheet is hidden so it won't let me print preview. I tried to make the workbooks visible then re-hide them upon completion. It is able to proceed with the print preview as I would like, but it errors out when it gets to "ws.Visible = False". The error reads "Run-time error'438': Object doesn't support this property or method. "
See code below...

VBA Code:
    'unhide sheets
    For Each ws In ThisWorkbook.Worksheets
        ws.Visible = True
    Next ws
    'Printpreview Array
    Sheets(SheetArray()).PrintPreview
   
    Sheets("Print Menu").Activate
   
    're-hide each sheet
    For Each ws In ThisWorkbook.Worksheets
       ws.Visible = False
    Next ws

I may need some type of except command to exclude the "print menu" from being hidden and leaving a workbook with no visible sheets.

Appreciate the help!
 
Last edited by a moderator:
Could be a solution:
VBA Code:
For Each ws In ThisWorkbook.Worksheets
    If Not ws.Name = "Print Menu" Then ws.Visible = False
Next ws
 
Upvote 0
Solution
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

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