macinjosh1
New Member
- Joined
- Nov 19, 2010
- Messages
- 24
I found this code from a really old post for password protecting a specific sheet in a workbook, but if the wrong password is put in, it locks up the whole workbook and excel, which I'd like to avoid.
I'm really a noobie when it comes to VBA, so if someone could help me with this, I'd really appreciate it. Or if there's something better, I'd take that too.
Code:
Public PvSh As String
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name = "Sheet2" Then
Num = ActiveWindow.Index
Windows(Num).Visible = False
If InputBox("Enter Password", "Password") <> "Mypassword" Then
Sheets(PvSh).Select
End If
Windows(Num).Visible = True
End If
End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
PvSh = Sh.Name
End Sub
I'm really a noobie when it comes to VBA, so if someone could help me with this, I'd really appreciate it. Or if there's something better, I'd take that too.