Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Nad Nad is offline
external usenet poster
 
Posts: 20
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default 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   Report Post  
Posted to microsoft.public.excel.programming
Nad Nad is offline
external usenet poster
 
Posts: 20
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Protecting a Sheet Shannan Excel Discussion (Misc queries) 7 September 30th 09 12:06 AM
protecting formulas without protecting sheet so grouping still wor JM Excel Discussion (Misc queries) 1 June 4th 09 06:42 AM
protecting a sheet des-sa[_2_] Excel Discussion (Misc queries) 3 January 15th 09 08:53 PM
Can't use tab after protecting sheet. tonyia Excel Worksheet Functions 0 March 21st 06 03:57 PM
Can't use tab after protecting sheet. snam Excel Discussion (Misc queries) 3 January 21st 05 02:54 PM


All times are GMT +1. The time now is 12:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"