<<Convert Excel Spreadsheets to Web Pages | Trading Software That Operates Within Excel | Convert Excel, Access & Other Databases | Merge Excel Files>>
Ozgrid, Experts in Microsoft Excel Spreadsheets

Password Protect Worksheet From Viewing

| | Information Helpful? Why Not Donate.

TRY OUT: Smart-VBA | Code-VBA | Analyzer-XL | Downloader-XL | Trader-XL| More Free Downloads.. Best Value: Finance Templates Bundle

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

Got any Excel Questions? 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 Become an ExcelUser Affiliate & Earn Money

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 [email protected] 31 days after purchase date.


Instant Download and Money Back Guarantee on Most Software

Try out:Analyzer XL |Downloader XL |Smart VBA |Trader XL Pro (best value) |ConsoXL | MergeXL | O2OLAP for Excel | MORE>>

Excel Trader PackageTechnical 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

Some of our more popular products are below...
Convert Excel Spreadsheets To Webpages | Trading In Excel | Construction Estimators | Finance Templates & Add-ins Bundle | Code-VBA | Smart-VBA | Print-VBA | Excel Data Manipulation & Analysis | Convert MS Office Applications To...... | Analyzer Excel | Downloader Excel | MSSQL Migration Toolkit | Monte Carlo Add-in | Excel Costing Templates