I need a way, when i open a workbook, to hide all sheets till the user enter
the correct password.
When the user enter the password i want be able to show all sheets.
Please, someone can help me?
Thanks
I tried the following to make a sheet hidden
Try same with some modifications for your need
But i think u must make at least one sheet active
cannot hide all sheets
U can do that for a extra blank sheet
IF u need to hide all the sheets then u can set the password to open
THat will be useful then VBA code
The following code should be in the workbook.
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)
pwd = Sheet1.Range("a2").Text 'this is the password to open the file
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" &
vbNewLine _
& "Password is case sensitive. Attempt " & lCount & "
of 3.", Title:="PASSWORD REQUIRED")
If strPass = vbNullString Then 'Cancelled
sLast.Select
Exit Sub
ElseIf strPass <> pwd Then 'InCorrect password
MsgBox "Password incorrect", vbCritical,
"Subodh"
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