Sunday 20 May 2018

vba - Reinstate worksheet protection upon save and close


I currently have a VBA code that will automatically unprotect all of the worksheets in my Excel 2016 file by username. enter image description here


Currently when I open the file it asks for a password. I do not want this to ask for a password, I just want it to unprotect ALL of the sheets if the user name of the person opening it matches what will be in the code.


Say I am authorized to make changes to the workbook and I open it and ALL of the sheets are unprotected. I make some changes, but want to automatically reinstate the protection I have set up on each sheet as I save the changes that were made.


The end user that will be filling out the worksheets does not have access to change anything opens the file and all of the protection that I have set up in in place and active. Currently I am using this code, but it is not working.


 Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("ADD-EXTEND").Protect Password:="SPAR"
ActiveWorkbook.Save
End Sub

P.S. This sub is below the code to unlock the sheets in the ThisWorkbook?



Answer



The screenshot below should be enough to get you started, it's pretty self-explanatory:


excel_protect_worksheet_on_close


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...