VBA & Macro Problems

How to Protect or Unprotect an Excel Sheet with a Checkbox in WPS Spreadsheets Using VBA

Maira MehtabMaira Mehtab Nov 13, 2026 870 views

Question details

The user wants to use a checkbox control and VBA code to automatically protect or unprotect a worksheet based on the checkbox state.

Protect or Unprotect a Worksheet with a Checkbox in WPS Spreadsheets
Product
WPS Spreadsheets (Excel for Mac macro-compatible)
Device & OS
macOS
Scenario
A user is working in a macro-enabled spreadsheet on macOS and wants to toggle sheet protection by clicking a checkbox instead of opening the Protect Sheet dialog each time.
Observed behavior
The worksheet should become protected when the checkbox is checked and unprotected when it is cleared.
Before you start

Make sure the Developer tab is enabled in WPS Spreadsheets and that you save the workbook as a macro-enabled .xlsm file. Also confirm that your macro security settings allow you to run VBA code.

Solution 1Recommended

Use a Form Control Checkbox and VBA to Automatically Protect or Unprotect a Worksheet

Use this when you want a single on-sheet checkbox to toggle worksheet protection without manually opening the Protect Sheet dialog every time.

The macro checks the checkbox value each time the control is clicked. If the value is 1, it calls Sheet1.Protect; otherwise, it calls Sheet1.Unprotect.

This approach works in WPS Spreadsheets and in Excel for Mac when macros are enabled and the workbook is saved as a macro-enabled file.

1
Enable the Developer tab

In WPS Spreadsheets, click the Menu icon and go to Options > Customize Ribbon, then enable Developer. If the Developer tab is already visible, skip this step.

2
Insert a checkbox Form control

Go to Developer > Insert > Form Controls and choose Check Box. Draw the checkbox on the sheet, then right-click it to edit its text or open Format Control.

3
Add the checkbox VBA macro

Press Alt+F11 or open Developer > Visual Basic to start the VBA editor. Insert a module and paste the following macro: Sub CheckBox1_Click() With Sheet1 If .Shapes("Check Box 1").ControlFormat.Value = 1 Then .Protect Else .Unprotect End If End With End Sub

4
Assign the macro to the checkbox

Right-click the checkbox on the worksheet and choose Assign Macro. Select CheckBox1_Click so the protection state updates each time the checkbox is clicked.

5
Save and enable macros

Save the workbook in a macro-enabled format such as .xlsm. Close and reopen the file, then enable macros when prompted so the checkbox runs the macro.

Use a Form Control Checkbox and VBA to Automatically Protect or Unprotect a Worksheet
Checkbox protection works after enabling macros: When macros are enabled, checking the box protects the worksheet and clearing it unprotects the worksheet. If the file is opened with macros disabled, the checkbox will not trigger the protection change.

Automate Worksheet Protection with a Checkbox in WPS Spreadsheets

Use the built-in Form Control checkbox and VBA editor in WPS Spreadsheets to run Sheet1.Protect and Sheet1.Unprotect automatically. The workbook remains compatible with Excel macro-enabled formats, so you can reuse the same checkbox logic across WPS Office and Excel for Mac.

  1. 1. Open your macro-enabled workbook: Launch WPS Spreadsheets and open the existing Excel workbook that contains the checkbox, or create a new workbook for the protection macro.
  2. 2. Insert a checkbox Form control: Go to Developer > Insert and choose the Check Box control under Form Controls. Draw the checkbox onto the worksheet.
  3. 3. Add and assign the VBA macro: Open the VBA editor with Alt+F11, paste the CheckBox1_Click macro, then right-click the checkbox and choose Assign Macro to link it.
  4. 4. Save and run: Save the file as a macro-enabled .xlsm workbook, reopen it, and enable macros so the checkbox can protect or unprotect the sheet.
Automatically protect and unprotect a sheet from a single checkbox instead of using the Review tab each time.Opens and saves Excel .xls and .xlsm macro-enabled workbooks with VBA compatibility.Free, lightweight Microsoft Excel alternative with a familiar ribbon and VBA editor.Runs the same Form control checkbox and macro pattern on macOS or Windows.
microsoft office alternative - wps office

Frequently Asked Questions

Why does nothing happen when I check the checkbox?

Usually macros are disabled. Reopen the workbook and choose Enable Macros when prompted, then verify the checkbox is still assigned to CheckBox1_Click.

Can I use this checkbox VBA macro in both WPS Spreadsheets and Excel for Mac?

Yes, the same Form Control checkbox and VBA code pattern works in both. Save the workbook in a macro-enabled format such as .xlsm and use the actual sheet code name in the macro.

Where is the Developer tab in WPS Spreadsheets?

Click the Menu icon, go to Options > Customize Ribbon, and enable Developer. You can also press Alt+F11 to open the VBA editor directly.

How do I add a password to the checkbox protection macro?

Add a password argument to the Protect and Unprotect calls, for example .Protect Password:="1234" and .Unprotect Password:="1234".