Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Macro to protect and unprotect all sheets of the current workbook

All,

Just wanted to share what finally came out of the guidance I received
from this ng. Maybe this will help someone else. Feedback appreciated:

These macros lets the user protect and unprotect all the sheets within
the current workbook. This macro asks the user for the password rather
than having the password as part of the code itself.
VR/
Lost




Sub UnProtectAllSheets()
Dim ws As Worksheet
Dim sOrigSheet As String
Dim sOrigCell As String
Dim sPWord As String
On Error GoTo Erro

Application.ScreenUpdating = False
sOrigSheet = ActiveSheet.Name
sOrigCell = ActiveCell.Address

sPWord = InputBox("Enter your UnProtect All password:", "UnProtect
All")
If sPWord "" Then
For Each ws In Worksheets
ws.Select
ws.unprotect Password:=sPWord
Next ws
End If
Application.GoTo Reference:=Worksheets("" & sOrigSheet &
"").Range("" & sOrigCell & "")
Application.ScreenUpdating = True
Erro:

Select Case Err
Case 0
MsgBox "Macro completed successfully (or was cancelled by user)."
Case Else
MsgBox "There is something wrong: " & Chr(10) & _
Err & ": " & Err.Description
End Select

Err.Clear

End Sub




Sub ProtectAllSheets()
Dim ws As Worksheet
Dim sOrigSheet As String
Dim sOrigCell As String
Dim sPWord As String
On Error GoTo Erro

Application.ScreenUpdating = False
sOrigSheet = ActiveSheet.Name
sOrigCell = ActiveCell.Address

sPWord = InputBox("Enter your Protect All password:", "Protect
All")
If sPWord "" Then
For Each ws In Worksheets
ws.Select
ws.protect Password:=sPWord
Next ws
End If
Application.GoTo Reference:=Worksheets("" & sOrigSheet &
"").Range("" & sOrigCell & "")
Application.ScreenUpdating = True
Erro:

Select Case Err
Case 0
MsgBox "Macro completed successfully (or was cancelled by user)."
Case Else
MsgBox "There is something wrong: " & Chr(10) & _
Err & ": " & Err.Description
End Select

Err.Clear

End Sub
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
Macro to test sheet and workbook protect and unprotect status. Lostguy Excel Programming 0 July 8th 08 01:41 AM
Macros for Protect/Unprotect all sheets in a workbook Paul Sheppard[_2_] Excel Programming 4 August 16th 05 03:36 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 Deeds[_2_] Excel Programming 1 May 27th 04 08:43 PM


All times are GMT +1. The time now is 11:26 PM.

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

About Us

"It's about Microsoft Excel"