Hide a sheet and Password protect it

adityad

New Member
Joined
Apr 1, 2004
Messages
3
I want to hide a sheet and I can do that. However, what I want to do it that when the user wants to view the sheet I just hid, he has to unhide and then enter a password. Right now tthere is no password.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
The only way I know to do this is with a macro. Hide the sheet as xlVeryHidden. That way the user can't see it in the sheets collection to unhide. To view the sheet they would have to execute a macro that would ask for a password (hardcoded) or even perhaps held on another 'very hidden' sheet. If they enter the correct password, have the macro unhide the sheet.


Of course you could protect the Workbook with a password, but then that will likely prevent them from doing a lot of other things you want them to do. Then again, maybe not, but it won't re-hide and re-protect the sheet when they are done.
 
Upvote 0
Welcome to the Board!

This is one way:

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Activate()
    pword = InputBox("Please Enter a Password", "Unhide Sheets")
    <SPAN style="color:#00007F">If</SPAN> pword <> "pword" <SPAN style="color:#00007F">Then</SPAN> ActiveSheet.Visible = <SPAN style="color:#00007F">False</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

The code goes in the module specific to the sheet that is hidden. When the user selects Format-->Sheet-->Unhide, the sheet will be unhidden, but they will be asxked for a pasxsword. If they get it wrong, the sheet will be rehidden.

Hope that helps,

Smitty
 
Upvote 0
One may not want the password to be found directly in the sheet code. Here comes an improved version of Smitty:

Private Sub Worksheet_Activate()
Dim pswrd As String
Dim pword As String
Call password_request(pswrd)
pword = InputBox("Please Enter a Password", "Unhide Sheets")
If pword <> pswrd Then ActiveSheet.Visible = False
End Sub

Sub password_request(pswrd As String)
Dim iFileNo As Integer
iFileNo = FreeFile
'open the file for reading
Open "C:\UPC\excel_password.txt" For Input As #iFileNo

' Read password
Input #iFileNo, pswrd

'close the file
Close #iFileNo
End Sub
 
Upvote 0
Hi,

I found this code on a previous post:

Private Sub Worksheet_Activate()
****pword = InputBox("Please Enter a Password", "Unhide Sheets")
****If pword <> "pword" Then ActiveSheet.Visible = False
End Sub

but when I paste it into the sheet in VBA I get the following error:

Compile Error
Syntax Error

And it highlights this portion of the code:
("Please Enter a Password", "Unhide Sheets")

Sorry for my ignorance, I am not too familiar with VBA, but where does the actual password go in the code? Right now, I do not have a password in the code...is that why I am getting this error?

Any help is much appreciated!!
 
Upvote 0
Delete the asterisks if you copied those into the code and replace them with a tab or space... I think they were meant as visual placeholders...
 
Upvote 0
Since all these approaches require VB, using VeryHidden would probably be easiest.
Also, I don't think the concern about the user seeing the password (if its hard coded into the VB routine) is not really valid. If the user can get into the VB Editor and knows VBA well enough to interpret the password correctly, any security is already blown.

The situation where the user is
1) able to get a password from a VBA module and
2) unable to break the security without that password
is a very rare.
 
Upvote 0
I have workbook that un-hides sheets when the correct password is entered... This is great but is there anyway to hide the password when it is entered?

Like instead of having "password" display when entered, have "********" display?

Thanks in advance.

GT
 
Upvote 0
I have workbook that un-hides sheets when the correct password is entered... This is great but is there anyway to hide the password when it is entered?

Like instead of having "password" display when entered, have "********" display?

Thanks in advance.

GT
See here

lenze
 
Upvote 0
There are examples about of using API to coerce an InputBox into displaying asterisks. IMHO, it is easier to make a simple userform with one textbox and two command buttons (OK and Cancel).

Create a new userform and plop a textbox onto it. In the properties window, check out the PasswordChar property.

Hope that helps,

Mark
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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