![]() |
| FREE Excel STUFF |
|
Search |
| Excel Help. Popular |
| NEW! Multiple Excel Search & Links |
| Excel Formulas |
| Excel Macros |
| Excel Newsletter |
| PRODUCTS |
| Up to $139.00 FREE! |
|
Categories & Search |
| Excel Templates |
| Excel Add-ins |
| Excel Training |
| More.... |
| OTHER |
| Excel Development |
|
|
NEW! More Books.. |
Add Excel Answers & Search To Your Google Toolbar Details |
Current Special! Complete Excel
Excel
Training Course
for Excel 97 - Excel 2003, only $145.00.
$59.95 Instant
Buy/Download,
30 Day Money Back Guarantee & Free
Excel Help for LIFE!
Got any Excel Questions? Free Excel Help
Password Protect Worksheet From Viewing
With the aid of some Excel VBA code placed the private module of the
Workbook Object (ThisWorkbook) we can password protect a Worksheet from
viewing to all those that do not know the password.
IMPORTANT: It should be noted that
this method is far from secure
and should not be used if the Worksheet contains highly sensitive
information. It is also addition to the general Worksheet protection and
uses the
UserInterfaceOnly
option of the
Protect Method. You should
also Protect/Lock Excel
VBA Code
The code shown below makes use of the
Worksheets
Code Name
.
It does not mask the password entry, but does stop after 3 failed attempts.
If you wish to mask the password, use a Textbox on a UserForm that has its
PasswordChar Property set to *. See
Protect
all Worksheets
for details.
The
Workbook_Open
procedure is there to ensure the Workbook does not open with the
un-viewable Worksheet being active.
To use this code: While in Excel proper, right click on the Excel icon, top left next to File and choose View Code it is in here you must paste the code below and change to suit your needs.
Dim sLast As Object
Private Sub Workbook_Open()
'Ensure Sheet1 is not the active sheet upon opening.
If Sheet1.Name = ActiveSheet.Name Then Sheet2.Select
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim strPass As String
Dim lCount As Long
If Sh.CodeName <> "Sheet1" Then
'Set sLast variable to the last active sheet _
This is then used to return the user to the _
last sheet they were on if password is not known _
or they Cancel.
Set sLast = Sh
Else
'Hide Columns
Sheet1.Columns.Hidden = True
'Allow 3 attempts at password
For lCount = 1 To 3
strPass = InputBox(Prompt:="Password Please", Title:="PASSWORD REQUIRED")
If strPass = vbNullString Then 'Cancelled
sLast.Select
Exit Sub
ElseIf strPass <> "Secret" Then 'InCorrect password
MsgBox "Password incorrect", vbCritical, "Ozgrid.com"
Else 'Correct Password
Exit For
End If
Next lCount
If lCount = 4 Then 'They use up their 3 attempts
sLast.Select
Exit Sub
Else 'Allow viewing
Sheet1.Columns.Hidden = False
End If
End If
End Sub
Excel Dashboard Reports & Excel Dashboard Charts 50% Off
Special! Free Choice of Complete Excel Training Course OR Excel Add-ins Collection on all purchases totaling over $64.00. ALL purchases totaling over $150.00 gets you BOTH! Purchases MUST be made via this site. Send payment proof to special@ozgrid.com 31 days after purchase date.
Instant Download and Money Back Guarantee on Most Software
Excel Trader Package Technical Analysis in Excel With $139.00 of FREE software!
Microsoft ® and Microsoft Excel ® are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft