Unprotect worksheet method in VBA

  • Thread starter Thread starter Bhupinder Rayat
  • Start date Start date
B

Bhupinder Rayat

Hi all,

I am using the unprotect method in VBA (on a sheet
containing a password);

ActiveSheet.Unprotect

which brings up the password prompt box. If the correct
password is entered and 'OK' is pressed, the sheet is
unprotected and then I have some "further code" that
runs.

If a wrong password is entered, I have a error handler
that deals with it.

The trouble is that when the password prompt box appears,
and I press the 'cancel' button, the "further code" still
runs.

How can I get the code to exit the sub after the 'cancel
button is pressed, so nothing happens?

Any help will be much appreciated.

Thanks,

Bhupinder Rayat
 
Bhupinder Rayat,

Something like this ?...
'--------------------------------------
Sub SheetProtectTest()
ActiveSheet.Unprotect
If ActiveSheet.ProtectContents = True Then
MsgBox "Still Protected"
Exit Sub
Else
MsgBox "Sheet Unprotected"
'do stuff
End If
End Sub
'--------------------------------------
Regards,
Jim Cone
San Francisco, USA
 
Jim,

works like a charm!

Thanks a bunch!

-----Original Message-----
Bhupinder Rayat,

Something like this ?...
'--------------------------------------
Sub SheetProtectTest()
ActiveSheet.Unprotect
If ActiveSheet.ProtectContents = True Then
MsgBox "Still Protected"
Exit Sub
Else
MsgBox "Sheet Unprotected"
'do stuff
End If
End Sub
'--------------------------------------
Regards,
Jim Cone
San Francisco, USA


message news:[email protected]...
.
 

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

Back
Top