In need of assistance, quite quickly if possible as I have goofed! The task was to password protect a single worksheet so that it prompted people for a password if they tried to view it. I checked the internet and found the following code:
Sub ToggleCompSheets()
Dim ConfirmHide As String
Application.ScreenUpdating = False
If Sheets("Sheet2").Visible = xlSheetVeryHidden Then
GetCompApproval
Sheets("Sheet2").Visible = xlSheetVisible
Sheets("Sheet2").Activate
Else
ConfirmHide = MsgBox(prompt:="This will hide the Sheet2 tab." & vbCr & vbCr & _
"You will need a password to access " & vbCr & _
"the tab if you choose to continue." & vbCr & vbCr & _
"Do you wish to continue?", Buttons:=vbYesNo, _
Title:="Hide Sheet2 Tab")
If ConfirmHide = vbNo Then
End
Else
Sheets("Sheet2").Visible = xlSheetVeryHidden
Sheets("Index").Activate
'Range("c8").Select
End If
End If
End Sub
Sub GetCompApproval()
Dim Password As String
Dim RetryPass As String
Password = InputBox(prompt:="Enter password to display Sheet2 tab", Title:="Password")
'MsgBox prompt:=Password
If Password = "" Then
End
ElseIf Password <> "1966" Then
RetryPass = MsgBox(prompt:="Sorry, password is incorrect" & vbCr & _
"contact Steve on Ext XXXX" & vbCr & _
"if you need a password", _
Title:="Access Denied", _
Buttons:=vbRetryCancel + vbExclamation)
If RetryPass = vbRetry Then
GetCompApproval
Else
End
End If
End If
End Sub
The problem is whilst the code did hide the worksheet I can not open it again, even from the VB editor. By looking at the code I think the password is 1966 but if I type that in it just returns to the VB editor. Can anybody see the problem or indeed suggest an easier way to do this.
Many thanks in advance
Sub ToggleCompSheets()
Dim ConfirmHide As String
Application.ScreenUpdating = False
If Sheets("Sheet2").Visible = xlSheetVeryHidden Then
GetCompApproval
Sheets("Sheet2").Visible = xlSheetVisible
Sheets("Sheet2").Activate
Else
ConfirmHide = MsgBox(prompt:="This will hide the Sheet2 tab." & vbCr & vbCr & _
"You will need a password to access " & vbCr & _
"the tab if you choose to continue." & vbCr & vbCr & _
"Do you wish to continue?", Buttons:=vbYesNo, _
Title:="Hide Sheet2 Tab")
If ConfirmHide = vbNo Then
End
Else
Sheets("Sheet2").Visible = xlSheetVeryHidden
Sheets("Index").Activate
'Range("c8").Select
End If
End If
End Sub
Sub GetCompApproval()
Dim Password As String
Dim RetryPass As String
Password = InputBox(prompt:="Enter password to display Sheet2 tab", Title:="Password")
'MsgBox prompt:=Password
If Password = "" Then
End
ElseIf Password <> "1966" Then
RetryPass = MsgBox(prompt:="Sorry, password is incorrect" & vbCr & _
"contact Steve on Ext XXXX" & vbCr & _
"if you need a password", _
Title:="Access Denied", _
Buttons:=vbRetryCancel + vbExclamation)
If RetryPass = vbRetry Then
GetCompApproval
Else
End
End If
End If
End Sub
The problem is whilst the code did hide the worksheet I can not open it again, even from the VB editor. By looking at the code I think the password is 1966 but if I type that in it just returns to the VB editor. Can anybody see the problem or indeed suggest an easier way to do this.
Many thanks in advance