View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Macros for Protect/Unprotect all sheets in a workbook

Hi Paul,

Try something like:

'======================
Sub unprotect_all()
Dim wks As Worksheet
Static PWORD As String


PWORD = InputBox("Please Enter Password")

On Error Resume Next
For Each wks In ActiveWorkbook.Worksheets
wks.Unprotect Password:=PWORD
Next
End Sub
'======================

'======================
Sub protect_all()
Dim wks As Worksheet
Static PWORD As String

PWORD = InputBox("Please Enter Password")

On Error Resume Next
For Each wks In ActiveWorkbook.Worksheets
wks.Protect Password:=PWORD
Next
End Sub
'======================

---
Regards,
Norman



"Paul Sheppard"
wrote in message
news:Paul.Sheppard.1t8fmf_1123146332.9964@excelfor um-nospam.com...

I have been using the macros below for Protecting/Unprotecting all
sheets in a workbook, they work ok unless the sheets are password
protected, in which case the Unprotect drop down appears and I have to
enter the password for each sheet

Is there any way to change the macros so that irrespective of how many
sheets there are I only have to enter the password once to either
unprotect them all or protect them all

If possible the macro should still run for sheets with no password

Sub unprotect_all()
Dim wks As Worksheet
On Error Resume Next
For Each wks In ActiveWorkbook.Worksheets
wks.Unprotect
Next
End Sub

Sub protect_all()
Dim wks As Worksheet
On Error Resume Next
For Each wks In ActiveWorkbook.Worksheets
wks.Protect
Next
End Sub


--
Paul Sheppard
------------------------------------------------------------------------
Paul Sheppard's Profile:
http://www.excelforum.com/member.php...o&userid=24783
View this thread: http://www.excelforum.com/showthread...hreadid=392821