Excel is what we do best
ALL YOUR EXCEL & SOFTWARE NEEDS
FREE Excel STUFF
Advanced Search Search Excel Content
PRODUCTS
Development
Contact Us
Excel Online

Password Protect Worksheet From Viewing

GIVE YOURSELF OR YOUR COMPANY 24/7 MICROSOFT EXCEL SUPPORT & QUESTIONS





Complete Excel Excel Training Course. Instant Buy/Download, 30 Day Money Back Guarantee

FREE DOWNLOADS SmartVBA | SmartVB6 | CodeVBA | CodeVB6 | Code Generator Pro | TraderXL Pro Package | Catalog | MORE..

Excel VBA: Password Protect Worksheet From Viewing. Prevent Worksheet Viewing

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 ObjectPrivate Sub Workbook_Open()    'Ensure Sheet1 is not the active sheet upon opening.    If Sheet1.Name = ActiveSheet.Name Then Sheet2.SelectEnd SubPrivate Sub Workbook_SheetActivate(ByVal Sh As Object)Dim strPass As StringDim 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 IfEnd 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. ALLpurchases 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 PackageTechnical Analysis in Excel With $139.00 of FREE software!

Add to GoogleSearch Tips FREEExcel Help

Microsoft ® and Microsoft Excel ® are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft

GIVE YOURSELF OR YOUR COMPANY 24/7 MICROSOFT EXCEL SUPPORT & QUESTIONS

Watch the latest videos on YouTube.com