Preserving cell formatting when protecting or unrprotecting

C

Colin Hayes

HI

I use this code to protect / unprotect my worksheets.


Sub Protect_Unprotect()
'
' Protect_Unprotect Macro

' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)


End Sub


What I'd like to do is to add a line or two which qualifies the protect
element so that it will allow for cell formatting once the sheet is
protected.

Can someone suggest a modification of the above ot allow for this?


Thanks.
 

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