Excel VBA Unprotect Sheet: Safe Methods and Examples

VBA & macros · Updated November 10, 2026

To unprotect a worksheet with VBA in Excel for Microsoft 365 on Windows, use Worksheet.Unprotect and supply the sheet’s password if it has one. For example, a macro can call Worksheets("Sheet1").Unprotect Password:="YourPassword"; without a password, call Worksheets("Sheet1").Unprotect. You must know the password when one is required—VBA is not a legitimate way to recover or bypass a forgotten password.

What worksheet protection does

Worksheet protection controls which changes users can make to a sheet. When protection is on, Excel can prevent edits to locked cells, changes to formatting, insertion or deletion of rows and columns, and other actions selected when the sheet was protected. It is commonly used to keep formulas or a prepared layout from being changed accidentally while leaving designated input cells editable.

Protection is not the same as encrypting a workbook. It is a set of editing restrictions, not a guarantee that the sheet’s contents are confidential. Do not use it to protect sensitive information from someone who has access to the workbook. File encryption and worksheet protection serve different purposes.

Unprotecting a sheet removes its worksheet-level restrictions. It does not automatically unprotect the workbook’s structure, remove a password required to open the file, or change protection on other sheets. Those are separate settings and may require separate credentials.

Run a VBA macro with the known password

The following macro asks for the password, targets the active worksheet, and reports whether Excel accepted it. Replace the active sheet selection with a named worksheet if you want the macro to affect a specific tab. Save a copy of the workbook before running any macro: VBA actions cannot be reversed with Ctrl+Z.

Sub UnprotectActiveSheet()
    Dim ws As Worksheet
    Dim sheetPassword As String

    ' Use the worksheet that is active when the macro runs.
    Set ws = ActiveSheet
    sheetPassword = InputBox("Enter the worksheet password:")

    ' Do not attempt an unprotect operation if the prompt was cancelled or left blank.
    If Len(sheetPassword) = 0 Then
        MsgBox "No password was entered. The sheet was not changed."
        Exit Sub
    End If

    On Error GoTo UnprotectFailed
    ws.Unprotect Password:=sheetPassword
    MsgBox "The worksheet is unprotected."
    Exit Sub

UnprotectFailed:
    MsgBox "Excel could not unprotect the worksheet. Check the password and try again."
End Sub

The input box does not conceal characters as you type, so avoid using it where other people can see the screen. The macro also does not store the password in the workbook. If the sheet is protected with no password, use the no-password form of the method instead; the prompt macro above deliberately treats a blank entry as a reason to stop.

Put the code in a module and run it

In desktop Excel for Microsoft 365 on Windows, first save a working copy. Open the Visual Basic Editor with Alt+F11, choose Insert > Module, paste the procedure into the module, then return to Excel. Run it from the editor with the cursor inside the procedure and press F5, or use Developer > Macros, select UnprotectActiveSheet, and choose Run. If the Developer tab is not visible, it can be enabled in Excel Options under Customize Ribbon.

When the macro runs, make sure the intended sheet is active before entering the password. A workbook may contain several tabs with similar names, and the active tab can change without being obvious if you are working in a large file. If you prefer to target a named sheet, change the assignment to Set ws = ThisWorkbook.Worksheets("Sheet1"), substituting the exact tab name. ThisWorkbook means the workbook containing the macro; it is usually safer than ActiveWorkbook when other workbooks are open.

Macros must be permitted by Excel’s security settings to run. Only enable macros in a workbook or project you trust. If the file is saved as an ordinary .xlsx workbook, it cannot store VBA code; use a macro-enabled .xlsm file to retain the macro. The macro changes the worksheet’s protection state, so check the result and save only if you intend to keep that change.

Unprotect a sheet that has no password

If the sheet was protected without a password, the method can be called without a password argument. A short procedure for a known tab looks like this:

Sub UnprotectSheetWithoutPassword()
    Dim ws As Worksheet

    ' Change the name to match the worksheet tab.
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    ws.Unprotect
End Sub

If Excel reports an error, the sheet may have a password, the name may not match a worksheet tab, or another condition may be preventing the operation. A chart sheet is not a worksheet, for example, and cannot be assigned to a variable declared as Worksheet. In a workbook with mixed sheet types, verify that the target is an actual worksheet.

Choose the right sheet and scope

A macro should target only the sheets that need to be changed. ActiveSheet is convenient for a one-off task, but it depends on which tab is selected at run time. A named reference is more predictable for repeatable work. Check the spelling, spaces, and punctuation in the tab name; a mismatch can cause a subscript-out-of-range error before Excel even attempts to unprotect anything.

For a routine that must process several worksheets, use a deliberate list of sheet names rather than removing protection indiscriminately from every tab. Before running a multi-sheet macro, consider whether some tabs are intentionally protected, whether users rely on those restrictions, and whether the same password applies to all of them. Different sheets can have different passwords and protection settings.

  • Use ActiveSheet for a one-time action when you can verify the selected tab.
  • Use ThisWorkbook.Worksheets("Exact tab name") when the macro should always affect one specific worksheet.
  • Process multiple named sheets only when you have permission and understand which restrictions will be removed.

After a sheet is unprotected, editing is no longer limited by its former protection settings. If the goal is simply to change one cell, unprotecting the sheet may be broader than necessary; ask the workbook owner whether there is an approved way to make that change.

Common errors and practical checks

A wrong password commonly causes Excel’s Unprotect method to fail, often with a run-time error. The macro above uses a basic error handler so the user receives a useful message rather than an unhandled interruption. The message is intentionally general: it cannot determine whether the password was mistyped or another issue occurred, so check the target and password before trying again.

If the macro appears to do nothing, confirm that it actually ran, that macros are enabled for this trusted file, and that you are looking at the worksheet it targeted. If it reports success but the tab still looks protected, verify the sheet name and try an edit that was previously blocked. Some cells may remain locked as a cell property, but locked status only restricts editing while sheet protection is enabled.

Another common source of confusion is workbook structure protection. It can restrict actions such as adding, deleting, moving, hiding, or renaming sheets. Removing a worksheet’s protection will not necessarily remove those workbook-level restrictions. Likewise, unprotecting one sheet does not change another sheet’s status.

VBA compared with the Excel ribbon

For a single sheet, the ribbon is often simpler than a macro. In desktop Excel for Windows, select the sheet and go to Review > Unprotect Sheet. If the sheet is password-protected, enter the password when prompted. The button may appear as Protect Sheet when protection is off. This method is easier to inspect and avoids storing or running code.

VBA is useful when the action is part of a controlled, repeatable workflow—for example, a trusted workbook that prepares sheets for an authorized update. It can also be used to target a particular worksheet by name, reducing the chance of selecting the wrong tab. But a macro does not grant special access: if Excel requires a password, the macro needs the correct password too. Choose the ribbon for occasional manual changes and VBA when automation provides a clear benefit.

Forgotten passwords and safety

If you do not know the password, contact the workbook’s owner or the person who set up the protection. Check approved documentation or a team password manager if one is used. Microsoft does not provide a way for VBA to reveal a forgotten worksheet-protection password. Be wary of code or online tools claiming to remove protection by exploiting file internals; they can damage a workbook, expose its contents, or violate organizational rules.

Worksheet protection should not be treated as encryption, but that does not make it appropriate to bypass someone else’s controls. A protected template may contain business rules, carefully designed formulas, or review safeguards. Get authorization before changing it, and preserve the original file so changes can be checked or discarded. If a workbook needs genuine confidentiality, use suitable file encryption and access controls rather than relying on a protected sheet.

Mac and Excel for the web

The VBA object model and the Worksheet.Unprotect method are also available in desktop Excel for Mac, though keyboard shortcuts and editor access can vary with the Mac model and keyboard settings. Use the Visual Basic command in the Excel ribbon or menus if the Windows Alt+F11 shortcut is unavailable; on some keyboards, a function-key combination may also require Fn. The Review tab provides the manual protection controls, with wording that can vary slightly by build.

Excel for the web does not run VBA macros. Open the workbook in the desktop app to use the VBA examples. If you only need a manual change, use the protection controls available in the version you are using; do not assume that a desktop VBA procedure will run in a browser. When a workbook contains macros, keep a macro-enabled file format if you need to preserve the code.

Frequently Asked Questions

What is the VBA command to unprotect an Excel sheet?
Use Worksheet.Unprotect. For a password-protected sheet, supply the known password with the Password argument; if there is no password, call Unprotect without that argument.

Can VBA unprotect a sheet if I forgot the password?
Not by supplying a valid password you do not know. Excel does not provide a VBA method to retrieve the forgotten password. Ask the workbook owner or use an approved recovery process instead of relying on bypass code.

How do I unprotect every sheet in a workbook?
Only automate this if you are authorized and know the password or passwords for the sheets. A workbook may use different passwords, and removing protection from every tab can undo intentional safeguards. For a small, controlled set of tabs, target each sheet explicitly and check the result.

Why does the VBA Unprotect command return an error?
Check that the sheet reference is correct, that the target is a worksheet, and that the password is exact. Also confirm that the macro is running in the intended workbook and that Excel permits it to run. A wrong password is a common cause of failure.

Does unprotecting a sheet unlock every cell permanently?
No. It turns off the sheet’s protection restrictions. Cells may still have their Locked property set, but that property does not prevent edits while sheet protection is off. If protection is turned on again, the locked-cell settings take effect under the selected protection options.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.