Sometimes you need to unprotect the worksheets in a workbook before continuing your work. If you find that you’re constantly unprotecting worksheets, this macro maybe help you.
Unprotect a Worksheet on Workbook Open
'------------------ ThisWorkbook ------------------
Private Sub Workbook_Open()
'Step 1: unprotect the sheet with a password
Sheets("Sheet1").Unprotect Password:="ExcelBaby"
End Sub
How This Macro Works
This code is triggered by the Workbook Open event. When you open a workbook, this event triggers, running the code within. This macro automatically unprotects the specified sheet with the given password when the workbook is opened.
The macro explicitly names the sheet we want to unprotect — Sheet1, in this case. Then it passes the password required to unprotect the sheet. Be aware that Excel passwords are case-sensitive, so pay attention to the exact password and capitalization that you are using.
How to Use This Macro
Most VBA code should be placed in Standard Modules unless specified.
If you see a comment '------------------ Modules------------------
in the code header that means put the code in a Standard Module. For more information, learn this course: Where should I put the Excel VBA code?
The following steps teach you how to put VBA code into a Standard Module:
- Activate the Visual Basic Editor by pressing ALT + F11.
- Right-click the project/workbook name in the Project Window.
- Choose Insert -> Module.
- Type or paste the code in the newly created module. You will probably need to change the sheet name, the range address, and the save location.
- Click Run button on the Visual Basic Editor toolbar.
- For more information, learn this course: Programming with Excel VBA