Checkbox problem

J

japfvg

Hi all,

I have a problem, I'm trying to modify the visible property or the value in
a checkbox inside a worksheet through a macro; I found in the F1 help of MS
Excel the way to do this, my code is like this:

Sub FiltrarBandas()
Sheets("HojaBase").CheckBoxes.Value = xlOff
Worksheets("HojaBase").OLEObjects("CheckBox6").Value = True
End Sub

But Excel gives me the error 1004 that the OLEObjects property cannot be
called from the WorkSheet class.

Do anyone knows how can I modify the checkbox properties from a macro??

Thank you very much!!
 
F

FSt1

hi
i got an error too but i did get this line to work.....

Worksheets("HojaBase").CheckBox6.Value = True

Regards
FSt1
 
D

Dave Peterson

It looks like you're mixing code for checkboxes from the Forms toolbar with code
for checkboxes from the control toolbox toolbar.

I'm guessing that this was not your intention.

That first line:
Worksheets("HojaBase").CheckBoxes.Value = xlOff
is for checkboxes from the Forms toolbar.

If those are what you're really using, try:
Worksheets("HojaBase").checkboxes("Check Box 6").Value = xlon

========

Unless you've renamed those Forms checkboxes, they'll have names like:
Check Box 1
Check Box 2
....
Check Box 99

The Checkboxes from the Control toolbox toolbar have names like:
Checkbox1
Checkbox2
....
Checkbox99

=============
If you're really using checkboxes from the control toolbox toolbar:

Option Explicit
Sub FiltrarBandas()
Dim OLEObj As OLEObject

For Each OLEObj In Worksheets("HojaBase").OLEObjects
If TypeOf OLEObj.Object Is MSForms.CheckBox Then
If LCase(OLEObj.Name) = LCase("checkbox6") Then
OLEObj.Object.Value = True
Else
OLEObj.Object.Value = False
End If
End If
Next OLEObj
End Sub
 
J

japfvg

Thank you for this answer but Excel told that this object doesn't acept the
property value.
 
J

japfvg

Thank you very much, you were right, I was mixing but I used the method for
the forms toolbar and it worked.

Thanks a lot again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top