View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Unprotect all sheets

Try the following code:

Sub AAA()
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
WS.Unprotect Password:="abc"
Next WS
'
' your code here
'
For Each WS In ThisWorkbook.Worksheets
WS.Protect Password:="abc"
Next WS
End Sub

You can protect the worksheets with the UserInterfaceOnly flag set to True
which will protect the worksheet against user actions but will allow VBA
code to do whatever it wants. This property is not saved with the workbook,
so you would need to protect the sheets in an Auto_Open procedure, which is
automatically run when the workbook opens.

Sub Auto_Open()
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
WS.Protect Password:="abc", userinterfaceonly:=True
Next WS
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"ADK" wrote in message
...
How do I unprotect all sheets (all with same password) and then after code
is done, protect all sheets with same password?