Excel sheet with both Form Control and ActiveX Check Boxes with Macro to change the colour when selected

14 Views Asked by At

Have Excel sheet with both Form Control and ActiveX Check Boxes with Macro to change the colour when selected.

When selected the Form Control check box colors are automatically getting changed, whereas for Activex need to run the macro manually. then only it works. Please assist to change the color for Activex as well automatically. Below are the codes which i am using for both.

Have Excel sheet with both Form Control and ActiveX Check Boxes with Macro to change the colour when selected.

When selected the Form Control check box colors are automatically getting changed, whereas for Activex need to run the macro manually. then only it works. Please assist to change the color for Activex as well automatically. Below are the codes which i am using for both.

**For Activex**'
Sub CheckboxLoop()
Dim objX As OLEObject
  With ActiveSheet
    For Each objX In .OLEObjects
       If TypeName(objX.Object) = "CheckBox" Then
         If objX.Object.Value = True Then
           objX.Object.BackColor = RGB(0, 255, 0)
         Else
           objX.Object.ForeColor = RGB(0, 0, 0)
           objX.Object.BackColor = RGB(255, 255, 255)
         End If
       End If
    Next
  End With
End Sub
'**For Form Control**'
Sub SetMacro()
Dim CB
   For Each CB In ActiveSheet.CheckBoxes
      If CB.OnAction = "" Then CB.OnAction = "CheckedUnchecked"
   Next CB
End Sub


Sub CheckedUnchecked()
  With ActiveSheet.Shapes(Application.Caller).DrawingObject
       If .Value = 1 Then
         .Interior.Color = RGB(0, 255, 0)
       Else
         .Interior.Color = RGB(255, 255, 255)
       End If
  End With
End Sub
0

There are 0 best solutions below