1. I added Option Explicit and when I complied (Alt-D) I got "Variable Not Defined" on the User1 line
Option Explicit
Dim bOK2Use As Boolean
Private Sub btnOK_Click()
Dim bError As Boolean
Dim sSName As String
Dim p As DocumentProperty
Dim bSetIt As Boolean
bOK2Use = False
bError = True
If Len(txtUser.Text) > 0 And Len(txtPass.Text) > 0 Then
bError = False
Select Case txtUser.Text
Case "User1"
sSName = "u1sheet"
If txtPass.Text <> "u1pass" Then bError = True
Case "User2"
sSName = "u2sheet"
If txtPass.Text <> "u2pass" Then bError = True
Case Else
bError = True
End Select
End If
If bError Then
MsgBox "Invalid User Name or Password"
Else
'Set document property
bSetIt = False
For Each p In ActiveWorkbook.CustomDocumentProperties
If p.Name = "auth" Then
p.Value = sSName
bSetIt = True
Exit For
End If
Next p
If Not bSetIt Then
ActiveWorkbook.CustomDocumentProperties.Add _
Name:="auth", LinkToContent:=False, _
Type:=msoPropertyTypeString, Value:=sSName
End If
Sheet1(User1).Visible = True
Sheet2(User2).Unprotect (txtPass.Text)
Sheet3(User3).Activate
bOK2Use = True
Unload UserForm1
End If
End Sub
Private Sub UserForm_Terminate()
If Not bOK2Use Then
ActiveWorkbook.Close (False)
End If
End Sub
2. 'Sheet1' is the Code Name for that sheet. It can also have a .Name like on the tabs at the bottom of the grid. I'm not sure about the User1, User2, and User3 so I can't suggest anything more specific
Sheet1(User1).Visible = True
Sheet2(User2).Unprotect (txtPass.Text)
Sheet3(User3).Activate
The way to refer to worksheets is like one of these
Dim User1 as String
Sheet1.Visible = True
Worksheets ("User1").Visible = True
User1 = "User1"
Worksheets (User1).Visible = True
3. I'm guessing you intended
Worksheets("User1").Visible = True
Worksheets("User2").Unprotect (txtPass.Text)
Worksheets("User3").Activate
but when I try to run it further, I get a "1004 unable to set the visible property of the worksheet class" so maybe the sample is corrupted