View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bug289 Bug289 is offline
external usenet poster
 
Posts: 8
Default Multiple sheet unprotection not working

These are the two subs. I took out the password prompt for the 'ProtectAll'
sub to simplify it while I get the unprotect working!

Sub ProtectAll()
Dim WS As Worksheet
'Dim Pword As String
'Pword = Application.InputBox("Enter password to lock spreadsheet",
"Password Check")
For Each WS In ActiveWorkbook.Worksheets
WS.Protect Password:="Fred"
Next WS
ThisWorkbook.Protect Password:="Fred", Structu=True

End Sub



Sub UnprotectAll()
Dim wks As Worksheet
Pword = InputBox("enter the password")
On Error GoTo endit
For Each wks In ActiveWorkbook.Worksheets
wks.Unprotect Password:=Pword
Next wks
ThisWorkbook.Unprotect Password:=Pword
endit:
MsgBox "Incorrect Password"
End Sub


"OssieMac" wrote:

Can you post the code you are using and mark the line that fails

--
Regards,

OssieMac


"Bug289" wrote:

Hi,
I have trawled through the substantial number of posts in the discussion
group on protecting and unprotecting multiple spreadsheets at the same
time...and been semi-successful.

I am protecting a spreadsheet so that my boss can edit the financially
sensitive areas of the sheets and then protect it so that they can't be
edited/seen by others entering data on the same sheets.

I want to make it as easy as possible for him to protect and unprotect
without having to find the VB editor so I have set up command buttons to run
a protect and unprotect sub. However, I need them to prompt him for a
password.

I can get protect to work without any issues but when I try to get it to
unprotect the code fails, flips to the VB editor and tells me the password is
incorrect even if it isn't.
The versions of code in the discussion group that involve an 'On Error
Goto..' line, 'Goto' everytime! I'm sure I'm missing something obvious but
can someone tell me what!