View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default Checkbox from control toolbar macro

Do you have more than one check box on different sheets with the same name?
Try this modification to my previous code (I just added ActiveSheet in front
of the checkbox name and changed the referenced check box to CheckBox2 to
match the code you showed in your last posting... again, change the name as
required)...

Sub Test()
With ActiveSheet.CheckBox2
.BackColor = vbRed
.ForeColor = vbWhite
.Caption = "HELLO"
End With
End Sub

The above code does work on my system. However, if you are still having
trouble with it, and if the code you posted is the only code that works for
you, then you can do it this way....

Sub Test()
With ActiveSheet.OLEObjects("CheckBox2").Object
.Caption = "HELLO"
.ForeColor = vbWhite
.BackColor = vbRed
End With
End Sub

Rick


"Patrick Bateman" wrote in
message ...
Hi,

i get the error "object required" when i tried it.
managed to find a way of setting the caption that works:

ActiveSheet.OLEObjects("checkbox2").Object.Caption = "Mechanical Complete"

but cant configure this to change the colour.

any ideas?

thankyou


"Rick Rothstein (MVP - VB)" wrote:

Yes, you just need to know the name of the control. For this example,
assume
the name is CheckBox1 (the default name Excel will give to the first
check
box)....

Sub Test()
With CheckBox1
.BackColor = vbRed
.ForeColor = vbWhite
.Caption = "HELLO"
End With
End Sub

Run the above macro and the check box will read HELLO in white letters on
a
red background. You can modify almost all of the controls (any control
you
place, not just a check box) using the structure above.

Rick


"Patrick Bateman" wrote in
message ...
Hi
is it possible to create a macro to change the colour and caption
properties
of a checkbox inserted friom the control toolbar?

thankyou for your help

Patrick