How to auto protect a specific worksheet in Excel?
To protect the worksheet may prevent others modifying the contents of your worksheet, sometimes, you need to edit your protected worksheet. In this case, you must unprotect the worksheet first, and then protect it again after modifying the content. However, most of us may forget to protect the worksheet again after finishing the editing. This article, I will talk about some methods to solve this task about auto protecting worksheet again.
There are no any other direct ways for us to auto protect the specific worksheet again in Excel, so you can create a VBA code to deal with it. After modifying the contents of the worksheet, please do as follows:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Then click ThisWorkbook from the left Project Explorer, double click it to open the Module, and then copy and paste following VBA code into the blank Module:
VBA code: Auto protect specific worksheet
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) If MsgBox("Reprotect Sheet Main?", vbYesNoCancel) = vbYes Then Sheets("Main").Protect ("123456") End If End Sub
3. And then save and close this code, a prompt box will pop out to remind you if you want to re-protect this specific worksheet, see screenshot:
4. Then click Yes button to protect this worksheet again, now, you need to save this workbook as Excel Macro-Enabled Workbook format. From now on, when you save or close this workbook, the above prompt box will pop out each time to remind you protecting your specific worksheet automatically.
Note: In the above code, the text Main is the worksheet name that you want to re-protect, and the number 123456 is the password of your protected sheet, you can change them to your need.
If you have Kutools for Excel, with its Worksheet Design feature, you can quickly and easily modify the protected sheet and then re-protect it again without any VBA code.
|Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 60 days.|
After installing Kutools for Excel, please do as following steps:
1. Go to your protected worksheet, and then click Enterprise > Worksheet Design, and a new Design tab will be displayed on the ribbon, see screenshots:
2. Under the Design tab, click Settings option in the Options group, and in the popped out Design Tools Settings dialog box, please check both Unprotect the worksheet before opening design tools option and Protect the worksheet before closing design tools option from the Protect section, and then enter the password of your protected worksheet into the Use Password text box, see screenshots:
3. After finishing the above settings, click OK to close the dialog, and then exit the Worksheet Design by clicking Close Worksheet Design to make this utility take effect. See screenshot:
4. In the protected worksheet, now, click the Enterprise > Worksheet Design to unprotect the worksheet and modify the content as you need, after editing the content, please click Close Worksheet Design to protect this worksheet again.