Hide and password protect worksheets

Linda21

New Member
Joined
Aug 2, 2010
Messages
38
<TABLE border=0 cellSpacing=0 cellPadding=2 width="100%"><TBODY><TR><TD align=left></TD></TR></TBODY></TABLE><TABLE border=0 cellSpacing=0 cellPadding=2 width="100%"><TBODY><TR><TD align=left></TD></TR></TBODY></TABLE><TABLE border=0 cellSpacing=0 cellPadding=2 width="100%"><TBODY><TR><TD align=left></TD></TR></TBODY></TABLE>I am trying to use the following code. It does not work for me as is. My sheet name is still 'Sheet1'.

I need to tweek it to disable viewing of all sheets. When user clicks on their sheet/tab, I want the password box to pop up. If the password is correct, I want the sheet to be editable during the session. Thanks!

The following was pulled from another source:

The Workbook_Open procedure is there to ensure the Workbook does not open with the un-viewable Worksheet being active.

To use this code: While in Excel proper, right click on the Excel icon, top left next to File and choose View Code it is in here you must paste the code below and change to suit your needs.
Dim sLast As Object
Private Sub Workbook_Open()
'Ensure Sheet1 is not the active sheet upon opening.
If Sheet1.Name = ActiveSheet.Name Then Sheet2.Select
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim strPass As String
Dim lCount As Long

If Sh.CodeName <> "Sheet1" Then
'Set sLast variable to the last active sheet _
This is then used to return the user to the _
last sheet they were on if password is not known _
or they Cancel.
Set sLast = Sh
Else
'Hide Columns
Sheet1.Columns.Hidden = True
'Allow 3 attempts at password
For lCount = 1 To 3
strPass = InputBox(Prompt:="Password Please", Title:="PASSWORD REQUIRED")
If strPass = vbNullString Then 'Cancelled
sLast.Select
Exit Sub
ElseIf strPass <> "Secret" Then 'InCorrect password
MsgBox "Password incorrect", vbCritical, "Ozgrid.com"
Else 'Correct Password
Exit For
End If
Next lCount

If lCount = 4 Then 'They use up their 3 attempts
sLast.Select
Exit Sub
Else 'Allow viewing
Sheet1.Columns.Hidden = False
End If
End If
End Sub
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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