Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to refer to ActiveX checkboxes on another worksheet by name within a variable

I have 57 checkboxes on one worksheet and I want code to check or uncheck 57 checkboxes on another worksheet which all have the same names (chk01, chk02, etc). Once I get the name of the checkbox from the first sheet, I can’t figure out how to make it check the same checkbox on the other sheet.

I get an error "Object doesn’t support this property or method" on the "ws.OLEObjects(checkboxName).Value = ws2.OLEObjects(checkboxName).Value" line.

Sub DeploymentPrep_Output_Create()

Dim ws, ws2 As Worksheet
Dim oj As OLEObject
Dim checkboxName As String

Set ws = Worksheets("Output")
Set ws2 = Worksheets("Inputs")
'Cycle through all of the check boxes in the ActiveSheet
For Each oj In ws.OLEObjects
If TypeName(oj.Object) = "CheckBox" Then
    checkboxName = oj.Name
    ws.OLEObjects(checkboxName).Value = ws2.OLEObjects(checkboxName).Value
End If

Next oj

End Sub

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

the Value property is to be called on the Object member of the OLEObject object

If TypeName(oj.Object) = "CheckBox" Then
    checkboxName = oj.Name
    oj.Object.Value = ws2.OLEObjects(checkboxName).Object.Value
End If
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading