Consulting

Results 1 to 6 of 6

Thread: Disable passwords/unhide sheet

  1. #1

    Disable passwords/unhide sheet

    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

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    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.
    [vba] 'Hide confidential sheet at startup
    If Environ("username") <> "Kenneth" Then Call HideSheets[/vba]
    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.

  3. #3
    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

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    Yes. You can IF() OR. If you have more than 2 users, I would use a Select Case.

  5. #5
    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

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    [vba] 'Hide confidential sheet at startup
    Select Case True
    Case Environ("username") = "Kenneth Hobson"
    Case Environ("username") = "StaceyO"
    Case Else
    Call HideSheets
    End Select[/vba]
    In VBE's Immediate Window to find the value of the username environment variable, type:
    [vba]?Environ("username")[/vba] 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •