protect and unprotect

A

Andrew

Hi - I am either missing something really simple or something else is
happening:

This works fine...
sub proc i_protect
Dim mySheet As Worksheet

For Each mySheet In Worksheets
mySheet.protect ("abc1234")
Next mySheet

end sub

This says the password is incorrect...
sub proc i_unprotect
Dim mySheet As Worksheet

For Each mySheet In Worksheets
mySheet.Unprotect ("abc1234")
Next mySheet

end sub

Any ideas?

Thanks

Andrew
 
D

Dr. Stephan Kassanke

In
Andrew said:
Hi - I am either missing something really simple or something else is
happening:

This works fine...
sub proc i_protect
Dim mySheet As Worksheet

For Each mySheet In Worksheets
mySheet.protect ("abc1234")
Next mySheet

end sub

This says the password is incorrect...
sub proc i_unprotect
Dim mySheet As Worksheet

For Each mySheet In Worksheets
mySheet.Unprotect ("abc1234")
Next mySheet

end sub

Any ideas?

Thanks

Andrew

Hi Andrew,

just tested it (I had to remove proc statements (what are these for?)).

Excel 2003 - works fine (protect and unprotect)

Are both procedures referring to the same workbook?

cheers,

Stephan
 
J

Jim Thomlinson

Just a guess but one of your sheets is protected with a different password.
Give this code a try...

Sub i_protect()
Dim mySheet As Worksheet

For Each mySheet In Worksheets
mySheet.Protect "abc1234"
Next mySheet

End Sub

Sub i_unprotect()
Dim mySheet As Worksheet

On Error GoTo ErrorHandler
For Each mySheet In Worksheets
mySheet.Unprotect "abc1234"
Next mySheet
Exit Sub
ErrorHandler:
MsgBox "Sheet " & mySheet.Name & " could not be unprotected.",
vbInformation
Resume Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top