Password protecting individual worksheets in excel so each person can only view and edit their own

%3CLINGO-SUB%20id%3D%22lingo-sub-1566266%22%20slang%3D%22en-US%22%3EPassword%20protecting%20individual%20worksheets%20in%20excel%20so%20each%20person%20can%20only%20view%20and%20edit%20their%20own%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1566266%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20there%2C%3C%2FP%3E%3CP%3EI%20am%20looking%20for%20a%20way%20to%20protect%20individual%20worksheets%20within%20in%20a%20workbook%20so%20that%20an%20admin%20could%20view%20and%20edit%20all%20worksheets%20but%20staff%20could%20only%20view%20and%20edit%20the%20worksheet%20they%20are%20assigned%20to.%26nbsp%3B%20Is%20this%20possible%3F%26nbsp%3B%20Can%20you%20help%20with%20instructions%20or%20point%20me%20to%20a%20tutorial%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1566266%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1566368%22%20slang%3D%22en-US%22%3ERe%3A%20Password%20protecting%20individual%20worksheets%20in%20excel%20so%20each%20person%20can%20only%20view%20and%20edit%20their%20o%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1566368%22%20slang%3D%22en-US%22%3EIt%20looks%20as%20though%20it%20would%20require%20some%20coding%2C%20if%20you%20want%20to%20automatically%20hide%20and%20show%20individual%20sheets%20based%20on%20individual%20identities%3CBR%20%2F%3E%3CBR%20%2F%3EI%20would%20probably%20keep%20it%20simple%2C%20adding%20a%20macro%20that%20would%20run%20when%20the%20spreadsheet%20was%20opened%2C%20look%20up%20the%20user's%20Windows%20login%20name%2C%20and%20use%20that%20to%20decide%20which%20sheet%20to%20open%20up.%20Each%20user's%20login%20name%20could%20be%20stored%20somewhere%20on%20their%20sheet%2C%20making%20it%20easy%20for%20macro%20to%20run%20through%20the%20sheets%20until%20it%20found%20the%20right%20login%20name.%20This%20is%20pretty%20easy%20to%20create.%3CBR%20%2F%3E%3CBR%20%2F%3EVBa%20can%20make%20sheets%20%22very%20hidden%22%2C%20too%2C%20meaning%20they%20won't%20even%20show%20up%20in%20the%20list%20of%20sheets%20from%20Excel%20menus.%3CBR%20%2F%3E%3CBR%20%2F%3EIs%20that%20the%20kind%20of%20thing%20you%20want%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1566378%22%20slang%3D%22en-US%22%3ERe%3A%20Password%20protecting%20individual%20worksheets%20in%20excel%20so%20each%20person%20can%20only%20view%20and%20edit%20their%20o%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1566378%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F749608%22%20target%3D%22_blank%22%3E%40Katie_V%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWorksheet%20protection%20is%20notoriously%20weak.%20Even%20someone%20with%20little%20skill%20can%20google%20the%20instructions%20to%20break%20it.%20But%2C%20if%20you%20still%20wanted%20to%20do%20it%2C%20then%20you%20would%20need%20to%20use%20VBA.%20You%20should%20be%20able%20to%20get%20the%20user%20id%20using%20the%20environ%20function.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%2C%20you%20would%20need%20to%20set%20up%20an%20event%20handler%20in%20the%20ThisWorkbook%20VBA%20module%20of%20your%20workbook%20to%20protect%20all%20sheets%20when%20opened%2C%20then%20get%20the%20user%20id%20and%20unprotect%20their%20sheet(s).%20You%20would%20also%20need%20to%20run%20the%20protectsheet%20routine%20before%20saving%20and%20the%20unprotect%20routine%20after%20saving.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20you%20would%20need%20to%20be%20sure%20to%20use%20the%20worksheet%20code%20names%2C%20which%20are%20viewable%20in%20the%20VBA%20project%20viewer%20or%20it%20is%20in%20the%20(Name)%20field%20when%20you%20click%20on%20the%20properties%20button%20in%20the%20developer%20tab%2C%20so%26nbsp%3B%20that%20users%20can't%20circumvent%20your%20macro%20by%20changing%20the%20worksheet%20tab%20name.%20And%2C%20you%20would%20have%20to%20protect%20the%20VBA%20project%20so%20they%20can't%20easily%20get%20your%20passwords%20(but%2C%20this%20is%20also%20easy%20to%20break%20if%20one%20googles%20it).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20the%20data%20is%20sensitive%20and%20you%20cannot%20risk%20users%20intentionally%20getting%20to%20other%20worksheets%2C%20then%20you'll%20have%20to%20find%20another%20way%20as%20Excel's%20internal%20%22security%22%20is%20not%20secure%20if%20people%20make%20any%20effort%20to%20break%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3BI%20attached%20an%20example%2C%20sort%20of%20a%20rough%20draft%2C%20to%20illustrate.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1566393%22%20slang%3D%22en-US%22%3ERe%3A%20Password%20protecting%20individual%20worksheets%20in%20excel%20so%20each%20person%20can%20only%20view%20and%20edit%20their%20o%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1566393%22%20slang%3D%22en-US%22%3E%3CP%3EThat's%20pretty%20much%20what%20I%20suggested%20above.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20agree%20that%20Excel's%20security%20is%20weak.%20However%2C%20if%20the%20users%20aren't%20savvy%20and%20the%20data%20is%20not%20very%20sensitive%2C%20it%20is%20probably%20OK.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20believe%2C%20however%2C%20there%20is%20a%20really%20secure%20option%2C%20for%20extreme%20situations.%20The%20entire%20contents%20of%20each%20sheet%20could%20be%20AES%20encrypted%20in%20place%20using%20passwords%20unique%20to%20each%20page.%20The%20code%20would%20request%20a%20password%20and%20anything%20except%20the%20correct%20pass%20would%20result%20in%20gibberish.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1566417%22%20slang%3D%22en-US%22%3ERe%3A%20Password%20protecting%20individual%20worksheets%20in%20excel%20so%20each%20person%20can%20only%20view%20and%20edit%20their%20o%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1566417%22%20slang%3D%22en-US%22%3EYes%2C%20I%20did%20not%20see%20your%20response%20until%20I%20refreshed%20the%20page.%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20the%20user%20has%20to%20enter%20a%20password%20to%20decrypt%20a%20worksheet%2C%20then%20that%20seems%20to%20be%20as%20much%20work%20as%20having%20them%20enter%20a%20password%20to%20unprotect%20the%20sheet.%20And%2C%20an%20admin%20would%20have%20to%20enter%20passwords%20for%20all%20of%20the%20sheets.%20I'm%20assuming%20that%20is%20what%20the%20OP%20is%20trying%20to%20avoid%2C%20otherwise%2C%20I%20wouldn't%20see%20the%20point%20in%20asking%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1566421%22%20slang%3D%22en-US%22%3ERe%3A%20Password%20protecting%20individual%20worksheets%20in%20excel%20so%20each%20person%20can%20only%20view%20and%20edit%20their%20o%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1566421%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F675152%22%20target%3D%22_blank%22%3E%40JMB17%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3EI%20suppose%20that%20is%20the%20problem%20with%20software%20that%20is%20designed%20to%20be%20open%20and%20collaborative%26nbsp%3B%20-%20it%20isn't%20good%20at%20being%20secretive!%3CBR%20%2F%3E%3CBR%20%2F%3EI%20have%20used%20AES%20encryption%20in%20several%20cases%20over%20the%20years%2C%20even%20encrypting%20individual%20rows%20of%20data%20with%20distinct%20passwords%2C%20so%20that%20users%20could%20%22log%20in%22%20and%20decrypt%20and%20use%20their%20individual%20data%20without%20the%20need%20for%20an%20internet%20connection.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1566456%22%20slang%3D%22en-US%22%3ERe%3A%20Password%20protecting%20individual%20worksheets%20in%20excel%20so%20each%20person%20can%20only%20view%20and%20edit%20their%20o%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1566456%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F749608%22%20target%3D%22_blank%22%3E%40Katie_V%3C%2FA%3E%26nbsp%3B%20%26nbsp%3BAs%20noted%20by%20previous%20commenters%2C%20Excel%20security%20is%20NOT%20secure!%20But%20I%20have%20done%20something%20similar%20to%20what%20you%20want%20for%20an%20internal%20document%20for%20training%20reports%20so%20employees%20can%20easily%20see%20their%20own%20reports%20but%20if%20they%20see%20others%20it%20isn't%20a%20big%20deal%20either.%26nbsp%3B%20I%20spent%20some%20time%20this%20evening%20initially%20'scrubbing'%20my%20training%20matrix%20%2F%20report%20and%20then%20decided%20to%20just%20scrap%20it%20and%20write%26nbsp%3B%20a%20very%20simple%20PW%20sheet%20control.%26nbsp%3B%20In%20the%20attached%20is%20the%20VBA%20code%20to%20basically%20do%20what%20you%20want.%26nbsp%3B%20On%20open%2C%20all%20sheets%20except%20%22Home%22%20are%20hidden.%26nbsp%3B%20Click%20the%20button%20%22Login%22%20to%20gain%20access.%26nbsp%3B%20The%20admin%20is%20Lotus%20with%20PW%20of%20123%20(thought%20that%20was%20funny).%26nbsp%3B%20i%20also%20have%20the%20PW%20for%20the%20VBA%20set%20to%20123%20and%20the%20master%20sheet%2Fworkbook%20PW%20set%20to%20123%20(that%20is%20a%20constant%20in%20the%20VBA%20on%20the%20frmPassword%20form%20code).%26nbsp%3B%20After%20opening%20with%20the%20Admin%20account%20(Lotus%20123)%20you%20can%20look%20at%20the%20%22Main%22%20tab%20to%20see%20how%20to%20add%20users%2C%20passwords%20and%20%22R%22%20or%20%22RW%22%20permissions%20for%20each%20page.%26nbsp%3B%20If%20the%20macro%20sees%20%22R%22%20or%20%22RW%22%20it%20makes%20the%20page%20visible%20and%20if%20it%20sees%20%22RW%22%20it%20also%20unlocks%20the%20page.%3C%2FP%3E%3CP%3EI%20really%20didn't%20intend%20to%20spend%20this%20much%20time%20on%20creating%20this%20for%20you%2Fothers%20but%20I%20did%20and%20it%20is%20well%20past%20my%20bedtime%20so%20I%20haven't%20tested%20everything%2C%20fixed%20everything%2C%20nor%20added%20all%20the%20features%20that%20would%20be%20nice.%20But%20don't%20worry%2C%20the%20bugs%20are%20included%20at%20no%20extra%20charge.%3C%2FP%3E%3CP%3EAGAIN%2C%20Excel%20is%20NOT%20secure%20and%20therefore%20I%20made%20no%20attempt%20to%20make%20this%20particularly%20secure.%26nbsp%3B%20You%20could%20use%20the%20%22very%20hidden%22%20and%20you%20could%20encrypt%20the%20passwords%20and%20much%20much%20more%2C%20but%20in%20the%20end%20it%20is%20still%20in%20excel%20and%20therefore%20inherently%20NOT%20particularly%20secure.%3C%2FP%3E%3CP%3ESo%20I%20hope%20this%20might%20be%20of%20some%20help%20to%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1566499%22%20slang%3D%22de-DE%22%3ESubject%3A%20Password%20protecting%20individual%20worksheets%20in%20excel%20so%20each%20person%20can%20only%20view%20and%20edit%20th%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1566499%22%20slang%3D%22de-DE%22%3E%3CBR%20%2F%3EApply%20different%20passwords%20or%20permissions%20to%20separate%20ranges%20in%20workbooks%20in%20Excel%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-gb%2Foffice%2Ftroubleshoot%2Fexcel%2Fapply-password-to-separate-range%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-gb%2Foffice%2Ftroubleshoot%2Fexcel%2Fapply-password-to-separate-range%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20or%20with%20VBA%20%3CBR%20%2F%3E%20uNam%20is%20the%20login%20name%20in%20the%20network.%20%3CBR%20%2F%3E%20If%20the%20employee%20now%20logs%20on%2C%20their%20associated%20sheet%20is%20shown.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20When%20the%20file%20is%20closed%2C%20the%20sheets%20are%20hidden%20and%20cannot%20be%20shown%20under%20Format%20-%20Sheet.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Private%20Sub%20Workbook_Open()%20%3CBR%20%2F%3E%20uNam%20%3D%20Environ(%22Username%22)%20%3CBR%20%2F%3E%20If%20uNam%20%3D%20%22yyy%22%20Then%20Sheets(%22Table1%22).%20Visible%20%3D%20True%20%3CBR%20%2F%3E%20If%20uNam%20%3D%20%22abc%22%20Then%20Sheets(%22Table2%22).%20Visible%20%3D%20True%20%3CBR%20%2F%3E%20End%20Sub%20Private%20Sub%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Workbook_BeforeClose(Cancel%20As%20Boolean)%20%3CBR%20%2F%3E%20Sheets(%22Table1%22).%20Visible%20%3D%20xlVeryHidden%20%3CBR%20%2F%3E%20Sheets(%22Table2%22).%20Visible%20%3D%20xlVeryHidden%20%3CBR%20%2F%3E%20End%20Sub%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Nikolino%20%3CBR%20%2F%3E%20I%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Hi there,

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?

7 Replies
Highlighted
It looks as though it would require some coding, if you want to automatically hide and show individual sheets based on individual identities

I would probably keep it simple, adding a macro that would run when the spreadsheet was opened, look up the user's Windows login name, and use that to decide which sheet to open up. Each user's login name could be stored somewhere on their sheet, making it easy for macro to run through the sheets until it found the right login name. This is pretty easy to create.

VBa can make sheets "very hidden", too, meaning they won't even show up in the list of sheets from Excel menus.

Is that the kind of thing you want?
Highlighted

@Katie_V 

 

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.

Highlighted

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.

Highlighted
Yes, I did not see your response until I refreshed the page.

If the user has to enter a password to decrypt a worksheet, then that seems to be as much work as having them enter a password to unprotect the sheet. And, an admin would have to enter passwords for all of the sheets. I'm assuming that is what the OP is trying to avoid, otherwise, I wouldn't see the point in asking?
Highlighted

@JMB17 
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.


Highlighted

@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.

Highlighted

Apply different passwords or permissions to separate ranges in workbooks in Excel
https://docs.microsoft.com/en-gb/office/troubleshoot/excel/apply-password-to-separate-range

or with VBA
uNam is the login name in the network.
If the employee now logs on, their associated sheet is shown.

When the file is closed, the sheets are hidden and cannot be shown under Format - Sheet.

Private Sub Workbook_Open()
uNam = Environ("Username")
If uNam = "yyy" Then Sheets("Tabelle1").Visible = True
If uNam = "abc" Then Sheets("Tabelle2").Visible = True
End Sub



Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Tabelle1").Visible = xlVeryHidden
Sheets("Tabelle2").Visible = xlVeryHidden
End Sub

Nikolino
I know I don't know anything (Socrates)