Skip to main content

Excel Macro: Unprotect a Worksheet on Workbook Open

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.

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:

  1. Activate the Visual Basic Editor by pressing ALT + F11.
  2. Right-click the project/workbook name in the Project Window.
  3. Choose Insert -> Module.
  4. 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.
  5. Click Run button on the Visual Basic Editor toolbar.
  6. For more information, learn this course: Programming with Excel VBA

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>