Print hidden sheets -

GregoryT

New Member
Joined
Oct 30, 2019
Messages
13
I used the following code to print a hidden sheet and my first sheet disappeared .......can anyone tell me what the problem was, please

TIA
GT

Sub PrintOnlyHiddenWorksheets()
Dim CurVis As Long
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
With sh
CurVis = .Visible
If CurVis >= 0 Then
.Visible = xlSheetVisible
.PrintOut
.Visible = CurVis
End If
End With
Next sh
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Works fine for me !!
By disappeared, do you mean hidden , deleted ??

Code:
Sub PrintOnlyHiddenWorksheets()
Dim CurVis As Long, sh As Worksheet
For Each sh In Worksheets
    With sh
    CurVis = .Visible
        If CurVis >= 0 Then
            .Visible = xlSheetVisible
            .PrintOut
            .Visible = CurVis
        End If
    End With
Next sh
End Sub
 
Upvote 0
The sheet gets erased, I am attempting to upload the workbook so you can have a look, but I cant see where to upload it.

Need coffee lol

Thanks
 
Upvote 0
You can't attach files in this forum.
I'd suggest looking at available options here
OR
Upload your file to a sharing site, Dropbox for instance, and then post the link back here
 
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,700
Members
448,293
Latest member
jin kazuya

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