Aug 04 2020 05:30 PM
Aug 04 2020 05:30 PM
I am looking for a way to protect individual worksheets within in a workbook so that an admin could view and edit all worksheets but staff could only view and edit the worksheet they are assigned to. Is this possible? Can you help with instructions or point me to a tutorial?
Aug 04 2020 08:16 PM
Aug 04 2020 08:29 PM
Worksheet protection is notoriously weak. Even someone with little skill can google the instructions to break it. But, if you still wanted to do it, then you would need to use VBA. You should be able to get the user id using the environ function.
And, you would need to set up an event handler in the ThisWorkbook VBA module of your workbook to protect all sheets when opened, then get the user id and unprotect their sheet(s). You would also need to run the protectsheet routine before saving and the unprotect routine after saving.
Also, you would need to be sure to use the worksheet code names, which are viewable in the VBA project viewer or it is in the (Name) field when you click on the properties button in the developer tab, so that users can't circumvent your macro by changing the worksheet tab name. And, you would have to protect the VBA project so they can't easily get your passwords (but, this is also easy to break if one googles it).
If the data is sensitive and you cannot risk users intentionally getting to other worksheets, then you'll have to find another way as Excel's internal "security" is not secure if people make any effort to break it.
I attached an example, sort of a rough draft, to illustrate.
Aug 04 2020 08:55 PM
That's pretty much what I suggested above.
I agree that Excel's security is weak. However, if the users aren't savvy and the data is not very sensitive, it is probably OK.
I believe, however, there is a really secure option, for extreme situations. The entire contents of each sheet could be AES encrypted in place using passwords unique to each page. The code would request a password and anything except the correct pass would result in gibberish.
Aug 04 2020 09:12 PM
Aug 04 2020 09:21 PM
I suppose that is the problem with software that is designed to be open and collaborative - it isn't good at being secretive!
I have used AES encryption in several cases over the years, even encrypting individual rows of data with distinct passwords, so that users could "log in" and decrypt and use their individual data without the need for an internet connection.
Aug 04 2020 10:13 PM
@Katie_V As noted by previous commenters, Excel security is NOT secure! But I have done something similar to what you want for an internal document for training reports so employees can easily see their own reports but if they see others it isn't a big deal either. I spent some time this evening initially 'scrubbing' my training matrix / report and then decided to just scrap it and write a very simple PW sheet control. In the attached is the VBA code to basically do what you want. On open, all sheets except "Home" are hidden. Click the button "Login" to gain access. The admin is Lotus with PW of 123 (thought that was funny). i also have the PW for the VBA set to 123 and the master sheet/workbook PW set to 123 (that is a constant in the VBA on the frmPassword form code). After opening with the Admin account (Lotus 123) you can look at the "Main" tab to see how to add users, passwords and "R" or "RW" permissions for each page. If the macro sees "R" or "RW" it makes the page visible and if it sees "RW" it also unlocks the page.
I really didn't intend to spend this much time on creating this for you/others but I did and it is well past my bedtime so I haven't tested everything, fixed everything, nor added all the features that would be nice. But don't worry, the bugs are included at no extra charge.
AGAIN, Excel is NOT secure and therefore I made no attempt to make this particularly secure. You could use the "very hidden" and you could encrypt the passwords and much much more, but in the end it is still in excel and therefore inherently NOT particularly secure.
So I hope this might be of some help to you.
Aug 04 2020 10:54 PM