Protect Excel Worksheets While Allowing Object Editing with VBA
Question details
The user wants to protect all Excel worksheets with VBA while allowing users to edit objects on protected sheets.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A workbook contains multiple worksheets whose cell contents should be protected while objects remain editable.
- Observed behavior
- The desired result is protected worksheet contents, editable objects, and continued macro access to protected sheets.
Open the workbook in a desktop version of Excel that supports VBA and save it as an Excel Macro-Enabled Workbook (.xlsm). If sheets are already protected, make sure you know their protection password; the example assumes the same password is used on all sheets.
Protect all worksheets without protecting drawing objects
Use one VBA macro to protect cell contents on every worksheet while leaving drawing objects editable.
In Excel, open Developer > Visual Basic, then choose Insert > Module.
Paste this code into the module. Replace the empty password with the shared worksheet protection password if needed: Sub ProtectAllSheets() Dim ws As Worksheet Const sheetPassword As String = "" For Each ws In ThisWorkbook.Worksheets If ws.ProtectContents Or ws.ProtectDrawingObjects Or ws.ProtectScenarios Then ws.Unprotect Password:=sheetPassword End If ws.Protect Password:=sheetPassword, DrawingObjects:=False, Contents:=True, UserInterfaceOnly:=True, AllowFormattingCells:=True Next ws End Sub
Return to Excel, choose Developer > Macros, select ProtectAllSheets, and click Run. On a protected sheet, test editing an object and modifying a locked cell.
In the VBA editor, double-click ThisWorkbook and add this event to reapply UserInterfaceOnly when the workbook opens: Private Sub Workbook_Open() ProtectAllSheets End Sub Save the workbook and enable macros when opening it from a trusted source.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with Excel files. Its format compatibility helps you move spreadsheets between applications; test VBA-dependent workbooks before relying on macros in WPS.

Frequently Asked Questions
Why can users edit objects but not locked cells?
The macro sets DrawingObjects:=False to leave drawing objects unprotected and Contents:=True to protect locked cell contents. Test the specific objects on each sheet after running Developer > Macros > ProtectAllSheets.
Why do macros lose access to protected sheets after reopening the workbook?
Excel does not retain UserInterfaceOnly protection across sessions. Add a Workbook_Open event in ThisWorkbook that calls ProtectAllSheets, and enable macros when opening the trusted workbook.
What if my worksheets have different protection passwords?
The example uses one shared password. Modify the code to supply the correct password for each worksheet before calling ws.Unprotect; otherwise, the macro will stop when it encounters a sheet it cannot unprotect.
Can users format cells without editing their contents?
Yes. The example uses AllowFormattingCells:=True, which permits cell formatting while locked cell contents remain protected. Set it to False if formatting should also be restricted.




