How would I clear all ActiveX checkboxes upon opening a file?

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
This ClearAllCheckBoxes() procedure is likely to do what you want. Paste the code below in the ThisWorkbook module.

VBA Code:
Private Sub Workbook_Open()
    Call ClearAllCheckBoxes
End Sub

Sub ClearAllCheckBoxes()

    Dim oWs         As Worksheet
    Dim oControl    As Object

    For Each oWs In ThisWorkbook.Worksheets
        For Each oControl In oWs.OLEObjects
            If TypeName(oControl.Object) = "CheckBox" Then
                oControl.Object.Enabled = True
                oControl.Object.Value = False
            End If
        Next oControl
    Next oWs
End Sub
 
Upvote 0
That would only be of use if the checkboxes had a linked cell, and it wouldn't help with enabling them.

To uncheck and enable all the checkboxes in a workbook you could use something like this.
VBA Code:
Sub ClearCheckboxes(wb As Workbook)
Dim ws As Worksheet
Dim ctl As OLEObject

    For Each ws In wb.Sheets
        For Each ctl In ws.OLEObjects
            If TypeName(ctl.Object) = "CheckBox" Then
                ctl.Object.Enabled = True
                ctl.Object.Value = False
            End If
        Next ctl
    Next ws
    
End Sub
 
Upvote 0
Solution
That would only be of use if the checkboxes had a linked cell, and it wouldn't help with enabling them.

To uncheck and enable all the checkboxes in a workbook you could use something like this.
VBA Code:
Sub ClearCheckboxes(wb As Workbook)
Dim ws As Worksheet
Dim ctl As OLEObject

    For Each ws In wb.Sheets
        For Each ctl In ws.OLEObjects
            If TypeName(ctl.Object) = "CheckBox" Then
                ctl.Object.Enabled = True
                ctl.Object.Value = False
            End If
        Next ctl
    Next ws
   
End Sub
Where do I copy and paste this?
 
Upvote 0
The code I posted would go in a standard module and you could call it from the Open event of the workbook in the ThisWorkbook module like this.
Code:
Private Sub Workbook_Open()
    ClearCheckboxes Me ' Me refers to the workbook the code is in
End Sub
 
Upvote 0
The code I posted would go in a standard module and you could call it from the Open event of the workbook in the ThisWorkbook module like this.
Code:
Private Sub Workbook_Open()
    ClearCheckboxes Me ' Me refers to the workbook the code is in
End Sub
So if my work book was named say test, would I call ClearCheckboxes(test)?
 
Upvote 0
So if my work book was named say test, would I call ClearCheckboxes(test)?
No, Me refers to the workbook the code is in regardless of it's name.

If you wanted to reset the checkboxes in a workbook name 'Test.xlsm' you would use this.
VBA Code:
ClearCheckBoxes Workbooks("Test.xlsm")
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top