Auto re-protect

cnicks17

New Member
Joined
Jan 10, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello!

I am fairly new at messing with Excel beyond the very basics. I have a schedule at work that I would like a specific worksheet to require a password each time it is opened. Sadly, the problem is that using the build in protection in Excel, some of the individuals who require access to view/edit this worksheet forget to re-protect the sheet.

I was hoping there was a way to have the sheet auto-protect and require a password each time that sheet is clicked on. Any suggestions would be much appreciated!

Thank you!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
add this to the worksheet you want it password protected:
VBA Code:
Private Sub Worksheet_Activate()
    Me.Protect Password:="yourpassword", UserInterfaceOnly:=True
End Sub

You can also create a macro that run on open, that will check if the sheet is protected, if not it will protect it.
VBA Code:
Private Sub Workbook_Open()
    If Not Me.Sheets("Sheet1").ProtectContents Then
        Me.Sheets("Sheet1").Protect Password:="yourpassword"
    End If
End Sub
 
Upvote 0
Hi there

You can try the following vba approach maybe...

VBA Code:
Private Sub Worksheet_Activate()
    Dim pass        As String
    pass = InputBox("Password?")
    If StrPtr(pass) = 0 Then
        MsgBox "User cancelled!", vbCritical, "Admin"
    ElseIf pass = vbNullString Then
        MsgBox "Please enter correct password!", vbCritical, "Admin"
    Else
        On Error GoTo Popup:
        ActiveSheet.Unprotect pass
        Exit Sub
        Popup:
        If Err.Number = 1004 Then
            MsgBox "Incorrect Password!", vbCritical, "Admin"
        End If
    End If
End Sub
Private Sub Worksheet_Deactivate()
    Worksheets("Sheet1").Protect "qwe"
End Sub
 
Upvote 0
VBA Code:
Private Sub Worksheet_Activate()
        Protect "pass123"
End Sub
This is all you need, just go to the sheet and click on worksheet activate event and paste this.
 
Upvote 0
Thank you both! These approaches both worked! Jimmy's addition of the pop-up Simplified my idea even further, thank you!
 
Upvote 0
Glad you got sorted and glad we could assist.... :cool:
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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