+ Reply to Thread
Results 1 to 13 of 13

Password protecting individual sheets in Excel

  1. #1
    Registered User
    Join Date
    10-11-2016
    Location
    Rock Hill, SC
    MS-Off Ver
    2013
    Posts
    10

    Question Password protecting individual sheets in Excel

    I've password protected each sheet in a file I'm currently working on but the code I found for it hides the sheet if the password is incorrect. That would be fine but this will be a shared file with roughly 25 users and each user only knows the password for their sheet. So if they accidentally select someone else's sheet or they type their password in wrong it will hide that sheet then move to the next one. That user won't know what the password is to the other sheet so they'll end up hiding every sheet in the workbook. I could hide every sheet and let the users unhide their sheet and type in the password but they would need to hide the sheet when they're done with it and I don't trust that they will do that. What I need is either a modified version of the code I'm currently using or a new version that would bring them back to sheet1 (the only unprotected sheet in the workbook) if the password is incorrect.

    The code I'm currently using to password protect each sheet is:

    Private Sub Worksheet_Activate()
    Const Password As String = "Jan"
    If InputBox("Please input the password to view this sheet.") <> Password Then
    Me.Visible = xlSheetHidden
    Else
    Me.Visible = xlSheetVisible
    End If
    End Sub

    And I'm also using this code to make sure the file always opens to sheet1:

    Private Sub Workbook_Open()
    Worksheets("Quick Look").Select
    End Sub

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,908

    Re: Password protecting individual sheets in Excel

    Out of interest, why do you want the pages to hide if the password is entered incorrectly?
    What's to stop them unhiding the sheet and trying again?

    Also, your code says "enter password to view this sheet". Surely in order to activate the sheet and fire this code the sheet must be visible already?


    If each user has a sheet of their own and presumably each user has a unique username, you could add some code to check the username against an expected value and only open the input box part of the code if they match. Would that work for you?

    BSB
    Last edited by BadlySpelledBuoy; 10-25-2016 at 02:44 PM.

  3. #3
    Registered User
    Join Date
    10-11-2016
    Location
    Rock Hill, SC
    MS-Off Ver
    2013
    Posts
    10

    Re: Password protecting individual sheets in Excel

    Well hiding the pages if the password is entered incorrectly isn't ideal, that's why I posted here. But there is nothing stopping them from unhiding the sheet and trying again, there is also nothing stopping them from viewing the code and seeing all the passwords. Security isn't really the issue here, the passwords act more to prevent the users from accidentally changing someone else's data than anything else. It also stops them from viewing some confidential information but that isn't quite as important.

    The sheet is visible when the password is prompted. I've made groups for each sheet so that, when collapsed, the only thing that's visible are employee names. So as long as the groups are collapsed seeing the sheets fine, though I haven't been able to get all of the groups to be collapsed when the file is opened but that's a problem for another post.

    Each user does have a username and that would work well, but, I don't have access to that information as it is "above my pay grade." The file is in a secured drive though so only those users will be able to see the file anyway.

    This file actually has a lot of problems because of the things my boss wants it to be able to do and if you're interested in seeing about it in more detail I made a post asking for help about it on Reddit (https://redd.it/59boyn) that has been unsuccessful so far. I didn't post all of those problems here though because people seem to get sidetracked by the minor problems and nothing useful ever gets solved for me.

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,908

    Re: Password protecting individual sheets in Excel

    Would it be possible to see a desensitized version of the file?

    It would make it far easier to help you with the issues above, as well as the ones you highlight on Reddit.

    BSB

  5. #5
    Registered User
    Join Date
    10-11-2016
    Location
    Rock Hill, SC
    MS-Off Ver
    2013
    Posts
    10

    Re: Password protecting individual sheets in Excel

    Sure, give me a second and I'll have that done

  6. #6
    Registered User
    Join Date
    10-11-2016
    Location
    Rock Hill, SC
    MS-Off Ver
    2013
    Posts
    10

    Re: Password protecting individual sheets in Excel

    Actually I don't know how to share the file with you...

  7. #7
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,908

    Re: Password protecting individual sheets in Excel

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Remember to desensitize the data.

    BSB

  8. #8
    Registered User
    Join Date
    10-11-2016
    Location
    Rock Hill, SC
    MS-Off Ver
    2013
    Posts
    10

    Re: Password protecting individual sheets in Excel

    Here is the desensitized version. There are normally 19 sheets but I cut it down because it only takes a couple to get the general idea and I didn't want to go through that much information.
    Attached Files Attached Files

  9. #9
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,908

    Re: Password protecting individual sheets in Excel

    Perhaps a slightly different approach would work here.
    You could password protect each sheet individually using the same passwords you have currently set in the VBA. Each user can unprotect their own sheet in order to view detail or makes changes.

    Then you could have a "before save event" that collapses all groups and reprotects all sheets whenever the workbook is saved.

    That would stop people being able to snoop about in data they're not privy to and would negate the worry of forgetting to protect sheets when finished with.

    It would also mean passwords weren't so visible by simply opening the VB editor or viewing the sheet code. Having said that, this can be avoided by password protecting the VB side of things.

    Keep in mind that Excel is not overly secure. It's possible to remove all passwords quite easily if you really want to and have a little know-how.

    BSB
    Last edited by BadlySpelledBuoy; 10-25-2016 at 04:24 PM.

  10. #10
    Registered User
    Join Date
    10-11-2016
    Location
    Rock Hill, SC
    MS-Off Ver
    2013
    Posts
    10

    Re: Password protecting individual sheets in Excel

    That would work very well, how could I do that?

  11. #11
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,908

    Re: Password protecting individual sheets in Excel

    In the attached I've applied sheet level protection with passwords using "Review / Protect Sheet". These passwords are currently set to the same as you had in the VBA in your example workbook.
    Sheets can be unprotected via "Review / Unprotect Sheet" using the relevant password.

    The code below is placed in the ThisWorkbook module (the same place you had your workbook open event code).
    Please Login or Register  to view this content.
    The code will fire each time the file is saved. The first part of the code will loop through all sheets in the workbook and close any expanded groups.
    The second part will protect all sheets with specified passwords.

    If you lock the VBA down via "Tools / VBAProject Properties / Protection" in the VB Editor then the passwords are safe from prying eyes (well as safe as Excel gets!).

    Is that of any use to you?

    BSB
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    10-11-2016
    Location
    Rock Hill, SC
    MS-Off Ver
    2013
    Posts
    10

    Re: Password protecting individual sheets in Excel

    That is perfect! Thank you so much for your help!

  13. #13
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,908

    Re: Password protecting individual sheets in Excel

    No problem at all. Happy I could help. Thanks for the rep point

    Don't forget to mark the thread as SOLVED if you're happy you have a working solution. Select Thread Tools from the menu link above and choose SOLVED.

    Also, a little tip for next time, don't forget to use code tags when you post your VBA or you'll face the wrath of The Moderators!

    Have a good day.

    BSB

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Protecting all sheets with a password.
    By Nitro2481 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 05-26-2016, 12:00 PM
  2. [SOLVED] Password protecting an individual sheet in a workbook
    By Nitro2481 in forum Excel General
    Replies: 17
    Last Post: 10-27-2014, 07:02 AM
  3. Protecting individual worksheets with a password
    By Nick_in_Dubai in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 01-13-2009, 04:35 AM
  4. Password protecting individual tabs in Excel 2003
    By WeatherMan in forum Excel General
    Replies: 3
    Last Post: 06-27-2008, 08:00 AM
  5. Password Protecting Sheets in Excel So Others Can't See Certain Sh
    By _ian2006_ in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-23-2006, 01:40 PM
  6. Protecting individual sheets
    By debra in forum Excel General
    Replies: 0
    Last Post: 12-06-2005, 02:21 PM
  7. [SOLVED] Password protecting sheets through VBA
    By Eithne R in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-26-2005, 06:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1