Protecting a Hidden Sheet

y2k

Board Regular
Joined
Feb 25, 2002
Messages
133
Is there any way to hide a sheet and request a password before the sheet can be un-hidden? I need to do this to Multiple sheets (namely 2001, 2002, 2003) but I don't want the password to be asked 3 times, just once to unhide all the sheets together. I know that this will probably have to be done using VBA and this is not a problem. Please can somebody help???????
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
If you hide allt he sheets you want to and then protect the workbook with a password, the following will unprotect and unhide all sheets (including charts) you have hidden: -

Public Sub UnprotectandUnhide()

Dim sh As Object
Dim Pass As String

Pass = InputBox("Please enter password to unhide sheets")

On Error GoTo ErrorHandler
ActiveWorkbook.Unprotect Pass

For Each sh In Sheets
If sh.Visible = False Then sh.Visible = True
Next sh

Exit Sub

ErrorHandler:
MsgBox "Wrong password, please re-enter"
On Error GoTo 0

End Sub
 
Upvote 0
Tht's exactly what I need. You're a genius!!!!! Thanks. I've got an Auto_Close Macro which hides the sheets if they're visible. The Macro you gave me is just perfect. However I have 2 questions. When I record the Auto_Close Macro, is there any way to specify the password? I don't want the user to be prompted for it. Secondly, not as important. When I type the password at the prompt (the one from your macro) the password appears. It's not protected from others viewing it. Can we change it so that it's protected and just appears as *'s???? I'm probably explaining myself very badly. Thanks again.
 
Upvote 0
For the Auto_Close macro, you could just use: -

ActiveWorkbook.Protect Password := "YourPassword"

As for the asterisks, I believe you can do this with a UserForm, but not with a normal InputBox. Maybe Juan Pablo or one of the other experts could help you out with that.
 
Upvote 0
Just realised, you could use a UserForm with a command button and a text box. Right-click on the textbox and select properties. Change the PasswordChr from blank to an asterisk. Double-click on the command button and enter the following in it's click-event: -

Call UnprotectandUnhide

Then amend the sub above to the one below: -

Public Sub UnprotectandUnhide()

Dim sh As Object

On Error GoTo ErrorHandler
ActiveWorkbook.Unprotect UserForm1.TextBox1.Text

For Each sh In Sheets
If sh.Visible = False Then sh.Visible = True
Next sh

Unload UserForm1
Exit Sub

ErrorHandler:
MsgBox "Wrong password, please re-enter"
On Error GoTo 0
Unload UserForm1

End Sub

You'll have to work out some way of showing the UserForm, maybe a command button on the sheet would be best.

HTH.
This message was edited by Mudface on 2002-03-01 05:20
 
Upvote 0

Forum statistics

Threads
1,214,527
Messages
6,120,057
Members
448,940
Latest member
mdusw

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