Can I require a password to VIEW a worksheet?

T

Tod

Here's a crude method. It'll show only one sheet, based on
the users password. If the user password is not recognized
it shows a Title sheet. You should also password-protect
your code.

You can play around with this to show more than one sheet,
etc.

tod


Private Sub Workbook_Open()
Dim ShowSheet As String

For Each ws In ThisWorkbook.Worksheets
If ws.Name = "Title" Then
ws.Visible = True
Else
ws.Visible = False
End If
Next ws

PW = InputBox("Enter your Password", "Password Entry")
Select Case PW
Case "Tod"
ShowSheet = "Tod"
Case "Wilma"
ShowSheet = "Wilma"
Case "Betty"
ShowSheet = "Betty"
Case "Fred"
ShowSheet = "Fred"
Case Else
ShowSheet = "Title"
End Select

For Each ws In ThisWorkbook.Worksheets
If ws.Name = ShowSheet Then
ws.Visible = True
Else
If ws.Name <> "Title" Then
ws.Visible = False
End If
End If
Next ws

If ShowSheet <> "Title" Then ThisWorkbook.Worksheets
("Title").Visible = False

End Sub
-----Original Message-----
Hi,
I am trying to set up a spreadsheet in which a user must
use a password to view specific worksheets. I don't want
them to be able to view anything on those specific
sheets. Excel's password protection seems to be either at
the workbook level or on elements within the worksheet.
I know that I could hide the contents of a worksheet and
then password protect that sheet, or I could hide a whole
worksheet and then protect the workbook structure, but
neither of those solutions are right for what I'm trying
to do.
 
J

Jonsson

Hi Suzanne



Here is another idea:


Sub pw()
'

'
Dim t1 As String
Dim I1 As Integer
Dim I2 As Integer
Dim Worksheets As Sheets

I1 = MsgBox("Go on?", 291, "Password?")
If I1 = 6 Then
For I2 = 1 To 3
t1 = InputBox("Password", "?", "")
If t1 = "simon" Or t1 = "mark" Then
Sheets("hid").Visible = True
Sheets("hid").Select
Exit Sub
Else
End If
Next 'I2

MsgBox "Access denied " & Chr(13) & "The programme will shut down"
ActiveWorkbook.Close savechanges:=True


End If

End Sub

//Thoma
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top