Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2004
    Posts
    78

    Unanswered: Unlock sheet using button

    Hi All,

    I have a sheet which is locked before distributing to users. I need to put a button on it so that the users who know the password can only unlock the sheet, else if password is blank or wrong it will display ERROR message and terminate. Any code will be useful.

    Thanks.

    ~BS

  2. #2
    Join Date
    Feb 2004
    Posts
    533
    I have done something like this only insted of putting the code in the workbook I created an unlock file. If the user had the file installed they could lock and unlock the workbook by clicking a button. The drawback to this if an unapproved person acquired the password file they could unlock the workbook plus you have to redistribute the file whenever you changed the password or added files to the workbook list. The advantage it is quick to use and you don't have to remember or give out the password, just the unlock file. The key file is hidden from view to prevent viewing by the user. This is a shot of the workbook list where protected files are listed.



    /
    ~

    Bill

  3. #3
    Join Date
    Nov 2004
    Location
    London
    Posts
    10
    just assign this bit of code to a button (make sure that your sheet is password protected)

    On Error GoTo WrongPassword
    ActiveSheet.Unprotect
    Exit Sub
    WrongPassword:
    MsgBox "Incorrect Password"

  4. #4
    Join Date
    Dec 2003
    Location
    San Diego, CA
    Posts
    153
    It can get fancier than this, but this is a fairly quick and dirty approach:
    Code:
    Private Sub CommandButton1_Click()
        Dim ans As String
            ans = InputBox("Please enter a password to unlock the sheet", "Password required")
            
            If ans <> "bigdog" Then
                MsgBox "Sorry Charlie, but you got it wrong", vbInformation + vbOKOnly, "Buy Bye"
                Exit Sub
            Else: ActiveSheet.Unprotect "password"
            End If
            
    End Sub
    Hope that helps,

    Smitty

Posting Permissions

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