Print button macro

GregT

New member
Joined
Nov 3, 2019
Messages
11
Reaction score
0
Points
1
Excel Version(s)
2016
Hi all,

I have a workbook with 4 sheets - 2 are hidden. The following code I am using works with the hidden sheet.

The problem is when I protect the sheets and workbook I get an error when I try to print the protected sheet or workbook. Can you suggest a workaround? Also I would like to view before print if that is possible...

TIA GT
----------------------------------------------------------------

Sub PrintSpecificSheet()
Dim wks As Worksheet

Set wks = ActiveWorkbook.Sheets("Printout")
If wks.Visible <> xlSheetVisible Then
Application.ScreenUpdating = False
wks.Visible = xlSheetVisible
wks.PrintOut
wks.Visible = xlSheetHidden
Application.ScreenUpdating = True
Else
wks.PrintOut
End If
Set wks = Nothing
End Sub
 
Last edited:
In your VBA, unprotect the sheet, print it, then re-protect.
 
Back
Top