VBA Excel Working With Protected Sheets
As a VBA programmer you will often have protected sheets where you would like your program to be able to modify but still remain protected from the users. There are different methods for accomplishing this. In the method I will explain a line of code is added to the start of the program which unprotects the sheets and another line of code is added add the end just before program execution ends to protect the sheets again:
In the code above I also two lines of code to change the Application.ScreenUpdating state. By setting Application.ScreenUpdating to false none of the changes your program makes to the sheets will be visible to the user. By reassigning the value to true, all the changes will be made visible. Not only will this improve the programs performance, but it will also prevent screen flickering.
There may be times that If it is vital that the end user does not see the password in your code (“123” in this case). If this is the case you can lock your macro from viewing:
If its the workbook that has been protected you can use the same concept above to unprotect the workbook: