I have a larger Excel file with multiple sheets and modules. In the code for each of these I need to protect or unprotect a password protected sheet temporarily in order to update certain protected parts.
So far I use one of the following lines which works but this means that the password appears multiple times throughout the code. Is there a way I can declare this password just once like a global variable and then just refer to this variable whenever needed so that it only has to be changed once if there is need for a change ? Also, would this reduce security on the file ?
To protect a sheet:
ActiveSheet.Protect Password:="MyPassword", UserInterfaceOnly:=True
To unprotect a sheet: