MarkVrenken
asked on
excel reference checkbox, vba
Dear experts,
i think it should be very simple to reference a checkbox but i don't seem to get it to work. i want to reference a checkbox on a excelsheet. below is my code
i get runtime error 438
cheers,
Mark
i think it should be very simple to reference a checkbox but i don't seem to get it to work. i want to reference a checkbox on a excelsheet. below is my code
Sub CheckBox1_Click()
If Workbooks("Book1").Worksheets("Deals Calc").CheckBox1 = True Then
Workbooks("Book1").Worksheets("Settings").Range("L1").Value = 1
Else
Workbooks("Book1").Worksheets("Settings").Range("L1").Value = 13
End If
End Sub
i get runtime error 438
cheers,
Mark
might change this ...
If Workbooks("Book1").Workshe ets("Deals Calc").CheckBox1
to...
If activeworkbook.activesheet .CheckBox1
If Workbooks("Book1").Workshe
to...
If activeworkbook.activesheet
ASKER
This is really stupid but i don't know where i can find/change the name of the control
The name of the workbook is referenced the right way, but i changed the name to book1 before posting it here
The name of the workbook is referenced the right way, but i changed the name to book1 before posting it here
ASKER
changing it to If activeworkbook.activesheet .CheckBox1 doesn't make a difference
ASKER
i think it's in the upper left corner next to the formula bar right? that says CheckBox1
ASKER
ActiveSheet.Shapes("Checkb ox1").OLEF ormat.Obje ct.Object. Value is working.
If the code is in the module of the worksheet that the control is on you can just use the name, CheckBox1.
ASKER
does anyone have an idea of why it only works like i do it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks:)
I added a Forms checkbox and ActiveX checkbox to the same worksheet, not at the same time.
This only worked with the ActiveX checkbox:
Like I said, if the code is in the same worksheet as the worksheet the checkbox is on you can just use it's name - you even get intellisense.
If you are using a Forms checkbox then you can use the sheets Checkboxes collection - see the attached file.
Checkboxes.xlsm
This only worked with the ActiveX checkbox:
ActiveSheet.Shapes("Checkbox1").OLEFormat.Object.Object.Value
When I tried it with the Forms checkbox it result in an 'Object doesn't support this property or method' error.Like I said, if the code is in the same worksheet as the worksheet the checkbox is on you can just use it's name - you even get intellisense.
If you are using a Forms checkbox then you can use the sheets Checkboxes collection - see the attached file.
Checkboxes.xlsm
and did you save the workbook to a different name (other than book1)?