ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Using VB to password protect, but sheet remains visible (https://www.excelbanter.com/excel-discussion-misc-queries/80436-using-vbulletin-password-protect-but-sheet-remains-visible.html)

JennyJeneralGraves

Using VB to password protect, but sheet remains visible
 
I used the following code to cause a password prompt to display upon clicking
on a tab in my workbook:

Private Sub Worksheet_Activate()
Dim strPassword As String
On Error Resume Next
Me.Protect Password:="123"
Me.Columns.Hidden = True

strPassword = InputBox("Enter password to view this sheet:")

If strPassword = "" Then
Me.Previous.Select
Exit Sub
ElseIf strPassword < "datagility" Then
MsgBox "Password Incorrect", , "Wrong password"
Me.Previous.Select
Exit Sub
Else
Me.Unprotect Password:="123"
Me.Columns.Hidden = True
End If
On Error GoTo 0
End Sub

Private Sub Worksheet_Deactivate()
On Error Resume Next
Me.Columns.Hidden = True
On Error GoTo 0
End Sub

**Problem is: when I click on the tab, the sheet is displayed in the
background behind the prompt. How can I make it so that it doesn't display at
all until the password is successfully entered?


All times are GMT +1. The time now is 12:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com