Here's the code to protect:
sheetcount = Worksheets.Count
For i = 1 To sheetcount
ActiveSheet.Protect
Next i
Here's the code to unprotect:
sheetcount = Worksheets.Count
For i = 1 To sheetcount
ActiveSheet.unProtect
Next i
Greg: Doesn't work; could I have missed something
Greg:
Tried for both protect and unprotect & got similar "runtime error '1004', "Unprotect method of Worksheet class failed" messages for both. Could I have missed something? I will paste complete code below in case. It does unprotect the active sheet when only one sheet is active, bit I was hoping for something that would work with multiple sheets.
Thanks.
Sub UnprotectActiveSheets()
'
' UnprotectActiveSheets Macro
' Macro recorded 6/15/01 by Dwight Hamilton
sheetcount = Worksheets.Count
For i = 1 To sheetcount
ActiveSheet.Unprotect
Next i
End Sub
Re: Greg: Doesn't work; could I have missed something
UnprotectActiveSheets Macro Macro recorded 6/15/01 by Dwight Hamilton
Dwight, you need to declare the variable "sheetcount". Put this before "sheetcount = Worksheets.Count".
Dim sheetcount As Integer
Barrie
Not a macro but you might want to look at this add in, it will do what you want and much more http://www.asap-utilities.com/
Re: Greg: Doesn't work; could I have missed something
Dwights Macro needs a slight mode to get it working.
Barrie is correct in his comments.
BUT......this macro will only protect the active sheet. Modify as follows......
Dim sheetcount As Integer
Dim i As Integer
Sub ProtectSh()
sheetcount = Worksheets.Count
For i = 1 To sheetcount
Sheets(i).Protect
Next i
End Sub
'Here 's the code to unprotect:
Sub UnprotectSh()
sheetcount = Worksheets.Count
For i = 1 To sheetcount
Sheets(i).Unprotect
Next i
End Sub
Ivan