Unprotect Password Prompt

aka_krakur

Active Member
Joined
Jan 31, 2006
Messages
438
I have a worksheet that is password protected. Various users will use this worksheet without the need to ever know the password.
however, It is also used by a couple of their managers who will need access to unlock.
Is there a way to have a macro to prompt for the password and verify it to the real password. (rather than have these managers go to the Tools, Protection, Unprotect Worksheet).

I already have something in place that on exit it automatically password protects it with the password of choice.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Attach the following code to a command button, or however else you want the user to call the unprotect function up.

Code:
    On Error Resume Next
    If ActiveSheet.ProtectContents = False Then
        MsgBox "Worksheet already unlocked!", vbCritical, "Fatal Error"
        Exit Sub
    End If
    
    myPass = InputBox("Enter worksheet password:", "Password Required")
    If myPass = vbNullString Or myPass = "" Then
        MsgBox "You did not enter a password!", vbCritical, "Fatal Error"
        Exit Sub
    End If
    
    ActiveSheet.Unprotect myPass
    
    If ActiveSheet.ProtectContents = True Then
        MsgBox "Invalid password.", vbCritical, "Fatal Error"
        Exit Sub
    End If
    
    MsgBox "Password accepted. Worksheet unlocked.", vbInformation, "Password Accepted"
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top