Worksheet protection

O

ordnance1

The code below is what I want to use to protect my worksheets (if a certain
condition is met) Everything works well in that the Protect sub prevents the
selection of any cells. My problem is with the UnProtect routine. When it
runs it asks for a password (which I would prefer not to have) and it
displays each worksheet as it runs. When the Protect code runs it does not
display each worksheet yet each one is protected.


Dim Shts As Worksheet
Sub UnProtectAllSheets()

Shts.Unprotect
Next


End Sub

Sub ProtectAllSheets()

For Each Shts In ThisWorkbook.Worksheets
Shts.Protect EnableSelection = xlNoSelection
Next

End Sub
 
B

Bob Umlas, Excel MVP

Sub UnProtectAllSheets()
Application.Screenupdating = False
for each Shts in Sheets
Shts.Unprotect password:="Put the password here"
Next
Application.Screenupdating = True
End Sub
Bob Umlas
Excel MVP
 
O

ordnance1

Thanks sir

I entered your code see below, and I protected each sheet with the password
snow but when the code runs I am prompted to enter the password for each
sheet.


Sub UnProtectAllSheets()

Application.ScreenUpdating = False

'Unprotects ALL worksheets
For Each Shts In ThisWorkbook.Worksheets
Shts.Unprotect Password:=snow
Next

Application.ScreenUpdating = True

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top