Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 "Bhupinder Rayat" wrote in message ... 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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 "Bhupinder Rayat" wrote in message ... 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 . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
unprotect worksheet when...... | Excel Discussion (Misc queries) | |||
Unprotect Worksheet. | Excel Discussion (Misc queries) | |||
unprotect worksheet | Excel Programming | |||
Unprotect Worksheet | Excel Programming | |||
Unprotect method run-time error | Excel Programming |