How to VeryHidden worksheets and display them with a password

K0st4din

Active Member
Joined
Feb 8, 2012
Messages
488
Office Version
  1. 2016
  2. 2013
  3. 2011
  4. 2010
  5. 2007
Platform
  1. Windows
Hello, everyone,
I love this excel so much that he can't put it into words.
Macros, I adore them.
The truth is that I searched in many sites, but very rarely there is a macro that is 100% consistent with what the user needs.
I could not find for my needs and therefore I ask you for help.
Here's what I need:
I have a workbook with 50 worksheets with different names.
I'm looking for a macro that always leaves a worksheet with a name (base) and the others with names ("peaches", "bananas", etc.) to be VeryHidden after the workbook closes (maybe Me.Save) .
And when I open the workbook, only the worksheet (base) is visible and I can show all the hidden worksheets with a password.
If the password is incorrect, do not show any of the hidden worksheets
I will be grateful for any help.
Greetings
 
I adjusted this to use the code name of the master sheet. And I corrected the variable to xlSheetVisible.
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim oneSheet As Worksheet

    Sheet1.Visible = xlSheetVisible
   
     For Each oneSheet In Me.Sheets
         If oneSheet.Name <> Sheet1.Name Then
             oneSheet.Visible = xlSheetVeryHidden
         End If
     Next oneSheet
    
End Sub

Private Sub Workbook_Open()
    Dim uiPassword
    Dim oneSheet As Worksheet
   
    Const soughtPassword As String = "password"
    uiPassword = Application.InputBox("Enter password", Default:=soughtPassword, Type:=2)
   
    If uiPassword = soughtPassword Then
        For Each oneSheet In Me.Sheets
            oneSheet.Visible = xlSheetVisible
        Next oneSheet
    Else
        MsgBox "wrong password"
    End If
End Sub
Hi, it works now, but I don't want the hidden worksheets to be displayed if the user doesn't know the password.
As soon as I open the workbook, the password window appears and it is visible (written), the password should be written there only if the user knows it. Otherwise, close the workbook.
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
The many and varied way you can get into the 'Hidden Sheets' made the whole exercise a total waste.
Are you talking about Hidden sheets or Very Hidden sheets?You can still get into Very Hidden sheets but it is harder if the VBA is protected.
What Mike has posted are Very Hidden sheets not Hidden sheets.
At the end of the day nothing in Excel is secure if you have a bit of knowledge.
 
Upvote 0
Are you talking about Hidden sheets or Very Hidden sheets?You can still get into Very Hidden sheets but it is harder if the VBA is protected.
What Mike has posted are Very Hidden sheets not Hidden sheets.
At the end of the day nothing in Excel is secure if you have a bit of knowledge.
Yes, I'm talking about VeryHidden sheets.
All macros are password locked in my table.
Thanks for joining
 
Upvote 0
Hi, it works now, but I don't want the hidden worksheets to be displayed if the user doesn't know the password.
As soon as I open the workbook, the password window appears and it is visible (written), the password should be written there only if the user knows it. Otherwise, close the workbook.
Then remove the Default argument of the Application.Input box. (And change the value of soughtPassword to be what you want.)
My providing a default was to highlight that this (or any other protection scheme) is not secure. Excel is not a place to keep secrets.
However, the VeryHidden nature of the sheets makes this a good way to insure that the user enables macros when opening the book.
 
Upvote 0
@mikerickson

Thank you very much for your cooperation.
I am 10,000% clear that this cannot protect anything, but still I know to whom I will send it and I know that it will not reach where it should not. :);)
 
Upvote 0

Forum statistics

Threads
1,217,388
Messages
6,136,313
Members
450,003
Latest member
AnnetteP

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top