+ Reply to Thread
Results 1 to 8 of 8

VBA to unlock password protected sheet using cmd button

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    879

    Question VBA to unlock password protected sheet using cmd button

    Hello happy campers!!

    I have

    Excel sheet, with 2 command buttons "Lock" & "Unlock"

    Press cmd button1, this will password protect the sheet with password as "secret" (have this set up already)
    Press cmd button 2, this will then produce a text box to require a user to put the specific password in to enable them to modify the sheet, otherwise it will stay locked.

    Any advice would be very much appreciated!
    galvinpaddy
    Last edited by galvinpaddy; 11-22-2011 at 11:16 AM. Reason: updated

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to unlock password protected sheet using cmd button

    You have not specified the issue you are facing.

  3. #3
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    879

    Re: VBA to unlock password protected sheet using cmd button

    i do apologise!

    Basically i would like the code that will make cmd button2 work.

    I require the button to open a text box, requesting the password, then if the password entered is correct then it will unlock the sheet for editing.
    I have a cmd button to lock the sheet with a set password, its just the text box & unlocking i am fighting with.

    Thank you very much
    galvinpaddy

  4. #4
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    879

    Re: VBA to unlock password protected sheet using cmd button

    Might be worth mentioning, the code i have for locking is simply:

    Sub ProtectOneSheet()
    Sheets("Sheet1").Protect Password:="secret"
    End Sub
    Not sure on how to modify this to request a password when the user clicks on cmd2 button (unlock)

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to unlock password protected sheet using cmd button

    This is the code you need -
    Sub unprotectsheet()
    UserAns = InputBox("Enter the password")
    
    If UserAns = "secret" Then
        Sheets("Sheet1").Unprotect Password:=UserAns
    End If
    
    End Sub

  6. #6
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    879

    Re: VBA to unlock password protected sheet using cmd button

    Great, thanks fella.
    Works a treat and quick response also!! nice one 10/10
    Mucho Gracias

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to unlock password protected sheet using cmd button

    My pleasure....thanks for the rep....

  8. #8
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    879

    Re: VBA to unlock password protected sheet using cmd button

    please mark as solved
    Thankyou

+ 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