How to protect an Excel workbook?

Updated

In This Article

How far a workbook must be protected depends on who receives it. Inside a team, Excel's own tools prevent accidents: locked cells, a fixed sheet structure, a locked VBA project and a password to open the file. For a workbook you sell or hand to people outside your control, the formulas and the code have to leave the file, because Excel's passwords prevent edits and not copying. This article gives the steps for both situations.

By default every cell is locked, but the lock only takes effect once the sheet is protected. First unlock the cells users may fill in: select them, open Format Cells (Ctrl+1), and on the Protection tab clear Locked. For cells whose formula should not appear in the formula bar, tick Hidden on the same tab.

The Protection tab of the Format Cells dialog in Excel, with the Locked and Hidden boxes

Then click Review > Protect Sheet, choose a password, and tick the actions users may still perform, such as formatting cells, sorting or using filters. Allow Users to Edit Ranges, on the same ribbon tab, opens specific ranges with their own password.

The Protect Sheet dialog in Excel: the password and the list of actions users are still allowed

What it stops: changes to locked cells and the actions you did not allow. What it does not stop: reading, selecting and copying the values, and other spreadsheet applications may ignore the protection altogether.

Review > Protect Workbook, with a password, prevents sheets from being added, deleted, moved, renamed, hidden or unhidden. It keeps a hidden sheet hidden, but not its values out of reach: a formula on another sheet can still read them, so it is not a protection of the contents.

The Protect Structure and Windows dialog in Excel

In the Visual Basic Editor (Alt+F11), open Tools > Project Properties, then the Protection tab, tick Lock project for viewing and set a password. Save and close the workbook: the lock applies from the next opening. Microsoft documents this as a way to keep the project from being viewed or edited; the code itself is not encrypted, and the lock is removed by free tools.

The Protection tab of the VBAProject Properties dialog in the Visual Basic Editor, with Lock project for viewing

File > Info > Protect Workbook > Encrypt with Password encrypts the file. Without the password, nobody opens it; with the password, everything in it is available. Keep the password somewhere safe: Microsoft cannot recover it.

The Protect Workbook menu on the Info page of Excel: Always Open Read-Only, Encrypt with Password, Protect Current Sheet, Protect Workbook Structure, Add a Digital Signature, Mark as Final

File > Info > Protect Workbook > Mark as Final makes the workbook read-only and shows a banner. It is a signal, not a lock: one click re-enables editing.

XLS Padlock compiles the workbook into a Windows EXE that the customer runs; the workbook opens in their own Microsoft Excel for Windows, 2010 or newer, 32-bit or 64-bit. The EXE holds the workbook in an encrypted container, so the customer never gets a plain XLSX or XLSM file on their disk. The steps below follow the pages of the tool, opened from its tab in the Excel ribbon.

XLS Padlock opened from its Excel ribbon tab, on the Application Settings page where the EXE path, the title and the packaging are set

XLS Padlock reads your workbook and writes the EXE; the customer gets the EXE, you keep the workbook. Keep it in your own files, and protect that copy with the steps of Part 1 if several people work on it.

Select the cells whose formulas must stay secret. They keep calculating in the EXE, but the formula bar shows a protected call instead of the formula, and if someone removes the protection the cells stop working. Protect the key cells rather than every cell: the XLS Padlock FAQ recommends it for performance.

The Manage Formulas to Protect window: the list of cells whose formulas are protected, filled from the right-click menu in Excel

A protected cell in the compiled workbook: the formula bar shows a protected call, =XLSPadlockForm(0), instead of the formula

Select the subs and functions to compile into bytecode. Their source leaves the workbook, replaced by one-line calls. UserForm code and event handlers stay as VBA; on the VBA Security page, block access to the Visual Basic Editor so that they cannot be opened in the EXE.

The VBA Compiler and Protection window of XLS Padlock, where the subs to compile are pasted

The VBA Security page: lock the VBA project or prevent access to the VBA editor

Decide, one by one, whether the EXE allows copying to the clipboard, printing, exporting to PDF, the formula bar and the right-click menu, and whether, and how, changes can be saved. Add an end-user licence agreement shown before the workbook opens if you want one.

The Restrictions page of XLS Padlock: printing, PDF export, right-click, clipboard copy, the formula bar and the ribbons can each be disabled

Choose between activation keys locked to one computer, online activation checked on a PHP server you host, a USB key or a dongle, and set an expiry by date, number of days or number of runs when the workbook is sold as a trial or a subscription. The built-in key generator makes the keys; a WooCommerce store or FastSpring can deliver them automatically.

The Licensing Options page of XLS Padlock, with the activation key requirement enabled

The Key Generator window of XLS Padlock, where a key is built for one customer

What the customer sees: the compiled workbook asks for an activation key before it opens

Build the EXE, then test it on a computer that is not yours, with the Excel version your customers use. Check that the protected cells calculate, that the compiled macros run, that the actions you disabled are disabled, and that a copied EXE asks for a key. Ship the EXE, optionally in a signed installer made with Paquet Builder.

The XLS Padlock tab in the Excel ribbon, with the Compile to EXE button

The dialog shown after a successful compilation: test the application, open its folder or distribute the EXE

SituationDo this
Colleagues fill in a form and must not break itPart 1, steps 1 and 2
Macros should not be edited by colleaguesPart 1, step 3
The file travels by e-mail or sits on a shared drivePart 1, step 4
The workbook is sold, or holds formulas and code you must keepPart 2
Only the macros must be protected, in Excel, Word, Access or PowerPointVBA Padlock