ganeshadu
New Member
- Joined
- Feb 20, 2024
- Messages
- 4
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
- Mobile
- Web
Thanks for welcoming in this forum.
Created Excel sheet in Office 365 Enterprise edition with both Form Control and ActiveX Check Boxes and 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 everytime to change the colour. Please assist to change the color for Activex as well automatically. Below are the codes which i am using for both. Added the below codes in module.
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
Created Excel sheet in Office 365 Enterprise edition with both Form Control and ActiveX Check Boxes and 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 everytime to change the colour. Please assist to change the color for Activex as well automatically. Below are the codes which i am using for both. Added the below codes in module.
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