How to Lock or Unlock All Excel Worksheets with Keyboard Shortcuts
Question details
The user wants to learn how to lock (protect) or unlock (unprotect) all worksheets in an Excel workbook simultaneously by assigning custom keyboard shortcuts to VBA macros.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Securing or editing multiple sheets efficiently without having to protect or unprotect each sheet individually.
- Observed behavior
- Users need to use VBA macros combined with shortcut assignments, as there is no direct built-in shortcut to protect or unprotect all sheets at once.
Ensure you have the VBA macro code ready for protecting and unprotecting sheets, and save your file as a Macro-Enabled Workbook (.xlsm) to preserve the code.
Assign Keyboard Shortcuts via the Macros Dialog
The simplest way to assign a shortcut key to an existing macro using Excel's built-in Macros options.
Press Alt+F8 on your keyboard to open the Macros dialog box, which displays all available macros in your workbook.
Click on the name of the macro you created to lock or unlock all worksheets to highlight it.
Click the 'Options' button on the right side of the dialog box.
In the 'Shortcut key' box, type the letter you want to use (e.g., 'L' for lock or 'U' for unlock). Click 'OK' to save the shortcut, then close the Macros dialog.

Use Application.OnKey in VBA Events
A more advanced method using VBA event handlers to assign specific shortcuts like Alt+L when the workbook opens and remove them when it closes.
Manage Macros and Protect Sheets Easily with WPS Office
WPS Spreadsheet fully supports VBA macros and sheet protection features, allowing you to easily automate tasks and secure your data using custom keyboard shortcuts.
- 1. Open Your Workbook: Launch WPS Spreadsheet and open your Macro-Enabled Workbook (.xlsm).
- 2. Access Developer Tools: Navigate to the 'Developer' tab on the top ribbon to access all macro and VBA features.
- 3. Manage Macros: Click on 'Macros' to open the dialog box where you can run, edit, or assign shortcuts to your sheet protection scripts.

Frequently Asked Questions
Why isn't my assigned macro shortcut working?
Ensure that macros are enabled in your Trust Center settings. Also, check if the shortcut combination you chose is overriding a critical system shortcut or is being blocked by another application.
Can I use Ctrl instead of Alt for macro shortcuts?
Yes. When using the Macros Options dialog (Alt+F8 > Options), Excel automatically assigns Ctrl + [Letter] or Ctrl + Shift + [Letter] as the shortcut for your macro.
How do I remove a keyboard shortcut from a macro?
Open the Macros dialog by pressing Alt+F8, select your macro, click 'Options', delete the character from the shortcut key box, and click 'OK'.




