VBA IF Then protect hidden worksheets code question

Lyryx

New Member
Joined
Aug 18, 2015
Messages
45
I'm trying to combine an IF Then function with my password protect hidden worksheet codes.

The idea is: when a worksheet is being unhidden, it will request a password, if the Password doesn't work the sheet will be hidden again.

Unfortunately, every time a worksheet that uses this code is accessed the password is requested again. Whether it has already been unhidden or not.


I know what I need to be done can be accomplished with a simple IF Then function, but I can't for the life of me get it to work.


here is an example of the code I am using.

Code:
Private Sub Worksheet_Show()If Sheet.Visible = False Then
Call Worksheet_unhide
End Sub
Private Sub Worksheet_unhide()
    pword = InputBox("Please Enter a Password", "Unhide Sheets")
    If pword <> "ILCbogo" Then ActiveSheet.Visible = False
End Sub


The second Private sub works fine, I thought the top sub would solve the issue I described earlier, but it just makes it so the worksheet never asks for a password.


Thanks in advance for your assistance.

There is no worry about hiding the password for this work book. It's not going to be used by anyone with an understanding of excel.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Don't rely on the "customer" to do anything right (like hide the pages again when finished working with them). I would add a Workbook_close event that hides and protects all sheets you want hidden every time the workbook closes. See the code I provided above, you should be able to make something work with that....
 
Upvote 0

Forum statistics

Threads
1,215,347
Messages
6,124,421
Members
449,157
Latest member
mytux

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