+ Reply to Thread
Results 1 to 4 of 4

Protecting Sheet

  1. #1
    Nad
    Guest

    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. #2
    somethinglikeant
    Guest

    Re: 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. #3
    Nad
    Guest

    Re: 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. #4
    NickHK
    Guest

    Re: 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" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D:[email protected]...
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1