Excel VBA Unprotect Sheet

If you just need to excel vba unprotect sheet and move on, the boxed answer at the top is all you need. The rest of this page is for when you want to understand why it works in Excel, adapt it to a trickier version, or make it robust enough to hand to a colleague. We keep the opening short on purpose — the depth is here when you want it, not in your way when you don’t.

Exact answer

In Excel: paste Sub UnprotectSheet() into the VBA editor (Alt + F11 → Insert ▸ Module), press F5 to run, and save as .xlsm to keep the macro. Excel for the web cannot create, run, or edit VBA macros. Open the workbook in the Excel desktop app to work with macros.

On this page8

VBA macro: Unprotect Sheet with VBA

Scroll code horizontally to see more
Sub UnprotectSheet()
    Dim ws As Worksheet
    Set ws = ActiveSheet
    On Error Resume Next
    ws.Unprotect Password:="MyPassword123"
    If ws.ProtectContents Then
        MsgBox "Wrong password — sheet remains protected.", vbCritical
    Else
        MsgBox "Sheet unprotected.", vbInformation
    End If
    On Error GoTo 0
End Sub

On Error Resume Next suppresses the runtime error when the password is wrong; the If check afterward lets you show a user-friendly message instead.

How to run this macro

  1. Press Alt + F11 to open the VBA editor.
  2. Insert > Module.
  3. Paste the code above.
  4. Press F5, or close the editor and run it from Developer > Macros.
  5. Save the file as .xlsm so the macro is kept.
▤Annotated stepsExcel
1

Open Excel and navigate to Developer ▸ Visual Basic (or press Alt + F11).

2

Select Insert ▸ Module from the menu bar inside the VBA editor.

3

Copy and paste Sub UnprotectSheet() into the Module.

4

Click anywhere inside the Sub body and press F5 to run.

5

Close the VBA editor and save the file as .xlsm.

Ctrl+CthenCtrl+Shift+V⌘+Cthen⌘+Ctrl+VPaste values · WindowsMac

What this does

Sub UnprotectSheet() is a ready-to-run VBA macro that handles unprotect a worksheet using a VBA macro without manual effort. VBA (Visual Basic for Applications) is Excel's built-in automation language: it can read every cell, loop through thousands of rows, and make decisions in milliseconds. To use it, open the VBA editor with Alt + F11, create a Module, paste the code, and press F5. The Unprotect Sheet with VBA macro will run immediately — no add-ins, no external tools, just Excel doing exactly what the code tells it to do. Read the code once before running it: note which sheets, ranges and files it touches and whether it deletes or overwrites anything. Macros run only in desktop Excel with macros enabled, and the code is kept only in a macro-enabled format such as .xlsm. Treat “excel vba unprotect sheet” as a small repeatable workflow rather than a one-off click you hope to remember next time. Use a small test block before the live file, so any surprise in the affected sheet shows up while it is still harmless. When this is a ribbon command, the selection matters more than the button: confirm the range, apply the command, then spot-check the output before saving. That turns a workspace setting that makes a big sheet comfortable to navigate into a method you can reuse, explain, and defend when the workbook leaves your screen.

A worked example

Example: a colleague sends you a large dataset and asks you to unprotect a worksheet using a VBA macro before handing it back. Open the VBA editor with Alt + F11, create a new Module, paste the Sub UnprotectSheet() code, and click Run (or press F5). Excel calls the Sub, runs through the sheet, and finishes the Unprotect Sheet with VBA task automatically. The whole operation takes seconds regardless of how many rows are involved — and because the macro is deterministic, it will produce the same result every time you run it on the same input. Reach for the Unprotect Sheet with VBA macro whenever unprotect a worksheet using a VBA macro is a task you repeat more than once, involves more than a handful of rows, or needs to be done consistently across multiple workbooks. VBA runs in milliseconds over data that would take minutes by hand, and it never makes the selection mistakes that manual workflows introduce when fatigue sets in. If the macro will be shared, add a comment at the top saying what it changes and which sheet it expects, and keep the workbook as .xlsm — saving it as .xlsx removes the code.

In Google Sheets

Google Sheets does not run VBA. A macro written for Excel has to be rewritten in Google Apps Script (Extensions ▸ Apps Script), and an .xlsm file converted to Sheets keeps its cells but drops the code. Nothing on this page is behind a login or a download: the exact answer is at the top, and the detail below it is there for when you need it. That is the whole promise here — the answer first, and just enough context to make it stick. Treat “excel vba unprotect sheet” as code you are responsible for: know what it changes, keep a copy of the workbook before running it and keep the file in a macro-enabled format. In Google Sheets and Excel for the web this code does not run; those need a different mechanism.

Common mistakes

  • Missing Option Explicit at the top of the module — adding it forces VBA to flag typos in variable names immediately, saving time debugging.
  • Not qualifying the range with the worksheet object — using Cells(1,1) without a ws. qualifier acts on whatever sheet is active; if the macro runs from a different sheet it may corrupt data. The pattern `Dim ws As Worksheet: Set ws = ActiveSheet` (or a specific sheet name) pins the action to the right place.
  • Forgetting that macros cannot be undone with Ctrl+Z once they have modified the sheet. Test on a copy of the workbook before running on live data.

Frequently asked questions

How do I run the Unprotect Sheet with VBA macro?

Press Alt + F11 to open the VBA editor, insert a Module (Insert ▸ Module), paste Sub UnprotectSheet() into the code pane, and press F5. Alternatively close the editor and run it from Developer ▸ Macros ▸ select "UnprotectSheet" ▸ Run.

Why won't my macro run — macros are disabled?

Excel blocks macros by default for files downloaded from the internet. Click the yellow security bar and choose "Enable Content" — that trusts this one workbook and is all that is normally needed. Leave File ▸ Options ▸ Trust Center ▸ Trust Center Settings ▸ Macro Settings on "Disable VBA macros with notification" rather than switching to "Enable all macros", which Microsoft itself marks not recommended. If the bar is red instead of yellow, the file carries Mark of the Web: close Excel, right-click the file, open Properties and tick Unblock. Also ensure the file is saved as .xlsm, not .xlsx.

Can I undo what the Unprotect Sheet with VBA macro did?

No — VBA actions generally cannot be undone with Ctrl+Z because they bypass Excel's undo stack. Always test Sub UnprotectSheet() on a backup copy of the workbook before running it on live data, or add explicit validation logic inside the macro before the destructive step.