Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Protecting Sheet
Hi
I used this code to protect my sheet Private Sub Worksheet_Activate() psw = InputBox("Please insert password to view data.", "Password Checker") If psw = "EPM" Then Sheets("ABD").Select Else MsgBox "Incorrect Password" End If End Sub But, even if i insert the wrong password my sheet become visible/active. Pls tell me where i am wrong. Thanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Protecting Sheet
Hi Nad,
You could probably do this without using macros, but here is a nice little solution hopefully:- First Protect the sheet by going to Tools Protection Protect Sheet set the password as the one you stated in your code EPM Click OK Then write this code into the Activate Worksheet module for this sheet:- :======================= Private Sub Worksheet_Activate() If ActiveSheet.ProtectContents = True Then psw = InputBox("Please insert password to view data.", "Password Checker") If psw = "EPM" Then Sheets("ABD").Unprotect ("EPM") Else MsgBox "Incorrect Password" End If End If End Sub :======================== Should work OK, let me know if there aare any problems somethinglikeant http://www.excel-ant.co.uk |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Protecting Sheet
Sorry, its not working. i got the same result as before.
Regards, Nad "somethinglikeant" wrote: Hi Nad, You could probably do this without using macros, but here is a nice little solution hopefully:- First Protect the sheet by going to Tools Protection Protect Sheet set the password as the one you stated in your code EPM Click OK Then write this code into the Activate Worksheet module for this sheet:- :======================= Private Sub Worksheet_Activate() If ActiveSheet.ProtectContents = True Then psw = InputBox("Please insert password to view data.", "Password Checker") If psw = "EPM" Then Sheets("ABD").Unprotect ("EPM") Else MsgBox "Incorrect Password" End If End If End Sub :======================== Should work OK, let me know if there aare any problems somethinglikeant http://www.excel-ant.co.uk |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Protecting Sheet
Assuming this code is on the sheet called "ABD", you need to reverse your
logic. As you are in the _Activate event, that sheet is about to br shown, so you have to do something to prevent it You can't cancel this event, so you have to .Activate another sheet. Private Sub Worksheet_Activate() psw = InputBox("Please insert password to view data.", "Password Checker") If psw = "EPM" Then 'Do nothing Else Worksheets(1).Activate End If End Sub NickHK "Nad" ... Hi I used this code to protect my sheet Private Sub Worksheet_Activate() psw = InputBox("Please insert password to view data.", "Password Checker") If psw = "EPM" Then Sheets("ABD").Select Else MsgBox "Incorrect Password" End If End Sub But, even if i insert the wrong password my sheet become visible/active. Pls tell me where i am wrong. Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Protecting a Sheet | Excel Discussion (Misc queries) | |||
protecting formulas without protecting sheet so grouping still wor | Excel Discussion (Misc queries) | |||
protecting a sheet | Excel Discussion (Misc queries) | |||
Can't use tab after protecting sheet. | Excel Worksheet Functions | |||
Can't use tab after protecting sheet. | Excel Discussion (Misc queries) |