PDA

View Full Version : Disable passwords/unhide sheet



StaceyO
07-28-2011, 10:06 AM
Hello,

I used the code from this site to hide a worksheet from certain users which can only be accessed with a password: (kb/getarticle.php?kb_id=380)

It works great but now I'd like to know if there is a macro that can disable that password and unhide the sheet permanently when the workbook is closed. For my purposes, once the workbook is assigned back to me, I don't need to hide the sheet anymore once it's been accessed. Is this possible?

Thanks in advance and of course, if this question has been answered elsewhere on this forum, please let me know where I can go!

Best,
Stacey

Kenneth Hobs
07-28-2011, 11:16 AM
Welcome to the forum!

You can use enviornment variable username or computername. To see the value, click Start > Run, and type %username%, OK.

Replace the line to hide the sheets with this line after you change Kenneth to your username.
'Hide confidential sheet at startup
If Environ("username") <> "Kenneth" Then Call HideSheets
For savvy users, these things can be worked around. At the least, I would hide all but one sheet when it closes and unhide the otheres at open.

StaceyO
07-28-2011, 11:46 AM
Thank you for your help! I'm going to try this and let you know. Could you have more than one username in the code? Sometimes other users besides myself will need to access the hidden sheet.

Let me know!

Regards,
Stacey

Kenneth Hobs
07-28-2011, 11:59 AM
Yes. You can IF() OR. If you have more than 2 users, I would use a Select Case.

StaceyO
07-28-2011, 12:57 PM
I'm having some difficulty with the expression. Am I on the right path with this:
If Environ("username" Is "name1" Or "name1" Or "name1") Then Call HideSheets

Kenneth Hobs
07-28-2011, 01:07 PM
'Hide confidential sheet at startup
Select Case True
Case Environ("username") = "Kenneth Hobson"
Case Environ("username") = "StaceyO"
Case Else
Call HideSheets
End Select
In VBE's Immediate Window to find the value of the username environment variable, type:
?Environ("username") Since the Start > Run method is not perfect. If you enclose the %username% in quotes when you do the Start > Run > "%username%", OK, you will get the full value of the environment variable.