VBA code to reset togglebutton colors.

Copper Contributor

have current code in commandbutton to RESET list of togglebuttons in front or a checklist of items  from red to green.

Want to modify, (duplicate code maybe?), this code into another commandbuddon to reset  a portion of these buttons to green and create other commandbutton to turn the others to red.

How can I accomplish this?

I am not very proficient in VBA so please be kind.

 

If I copy this code, what do I change to keep the code separate and  not duplicate.

Option Explicit

Public MyButtons As New Collection

Private Sub Workbook_Open()
Dim OO As OLEObject
Dim MBE As MyButtonEvent
For Each OO In Sheets(1).OLEObjects
If OO.progID = "Forms.ToggleButton.1" Then
'Create a new object
Set MBE = New MyButtonEvent
'Assign the button
Set MBE.MyButton = OO.Object
'Keep it alive in the collection
MyButtons.Add MBE
End If
Next
End Sub

Sub ResetButtons()
Dim MBE As MyButtonEvent
For Each MBE In MyButtons
With MBE.MyButton
.Value = False
.BackColor = vbGreen
End WithNext
End Sub

0 Replies