Printing a protected wsorksheet

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
I have a worksheet with a number of hidden and unhidden cells which I need to print. I have a code that works when the sheet is not protected, but I need to modify it to work when the sheet is protected. Any ideas?

Sub DSRW1()
Rows("66:117").Hidden = False
Range("B66:G117").PrintPreview
Rows("66:80").Hidden = True
Rows("82:85").Hidden = True
Rows("87:93").Hidden = True
Rows("96:107").Hidden = True
Rows("109:115").Hidden = True
End Sub

Thanks,

Andrew

P.S. If I wanted the range to not include column C, how would I do that?
 
Can't you just add a command to unprotect the worksheet before your code, and another command to protect it again at the end ?
 
Upvote 0
This will unprotect it.
Code:
ActiveSheet.Unprotect "PASSWORD"
Replace "PASSWORD" with whatever the worksheet password is.
It may not have a password at all, in which case you can ignore that part.

To turn protection back on, something like this
Code:
ActiveSheet.Protect "PASSWORD"
    ActiveSheet.EnableSelection = xlUnlockedCells
    ActiveSheet.EnableSelection = xlLockedCells
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Note that when you choose to protect a worksheet, there is a list of options of things that you can still allow users to do.
The example I have posted is one that I use, where I want to allow them to do specific things, and not others.
You might want to allow them to do different things.
Try recording a macro while you protect the worksheet and set the options you want, and you'll get some variation of this code.
 
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