Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macros for Protect/Unprotect all sheets in a workbook


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macros for Protect/Unprotect all sheets in a workbook


Thanks Norma

--
Paul Sheppar
-----------------------------------------------------------------------
Paul Sheppard's Profile: http://www.excelforum.com/member.php...fo&userid=2478
View this thread: http://www.excelforum.com/showthread.php?threadid=39282

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macros for Protect/Unprotect all sheets in a workbook


I am sorry to Bump an old post, but I just have a question. I wa
looking for an answer and did a search, and found my answer in thi
thread. Thats how I got here. Anyways...

In the code above, there is the line:
"On Error Resume Next"

I understand the rest of the code, and what the subs do and whatnot
but I am a little confused as to the purpose of this line. I woul
just like an explination if anyone can provide one. Thank you

--
ph
-----------------------------------------------------------------------
ph8's Profile: http://www.excelforum.com/member.php...fo&userid=1987
View this thread: http://www.excelforum.com/showthread.php?threadid=39282

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macros for Protect/Unprotect all sheets in a workbook


on resume next is used to ignore or handle errors yourself

if an error occurs the code will continue on the next line

in this case the error raised if the password is incorrect is ignored
and another try is made.
the real bad part of this code is the lack of the statement:

Code:
--------------------
On error goto 0
--------------------

just before the end of the sub. in this piece of $#%^$%^ you will end
up ignoring errors in the rest of your code resulting in very
unpredictable results.
So take it from me for every _resume_next___ You should have at least 1
_goto_0_


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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Protect/unprotect all sheets at once? wx4usa New Users to Excel 4 July 22nd 08 12:08 AM
Protect-Unprotect all the sheets Gary Excel Worksheet Functions 7 February 26th 07 08:13 PM
Macros for Protect/Unprotect all sheets in a workbook Paul Sheppard Excel Discussion (Misc queries) 2 August 4th 05 04:30 PM
Protect / Unprotect Sheets Rob F[_2_] Excel Programming 3 August 10th 04 02:27 PM
Protect/Unprotect Sheets Deeds[_2_] Excel Programming 1 May 27th 04 08:43 PM


All times are GMT +1. The time now is 10:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"