I want all command buttons to change color from a VBA code

I have 50 generators, which is a lot of buttons. Its easy to strong arm this, and write a line specifying each one, but I'm sure there is an elegant solution where I could say:

For Each Commandbutton in ThisDisplay.objects

.BackColor = color1

.ForeColor = color2

next CommandButton

but for now I'm stuck with this ugliness:

  ButtonSR1.BackColor = color1

  ButtonSR1.ForeColor = color2

 

  ButtonSR2.BackColor = color1

  ButtonSR2.ForeColor = color2

 

  ButtonWR1.BackColor = color1

  ButtonWR1.ForeColor = color2

 

  ButtonWR2.BackColor = color1

  ButtonWR2.ForeColor = color2

 

  ButtonWR3.BackColor = color1

  ButtonWR3.ForeColor = color2

 

this goes on for a while, I'll spare you the rest...

Parents
  • is there anything i can do to draw attention to this? I've been struggling with it for a long time, and my code is repeated so many times. The biggest problem is that any time I make a change, I have to add/remove those lines in many different subs, and i am prone to missing things.

     

    Thank you in advance. I'm sorry if this question is stupid, but I don't know where else to look.

Reply
  • is there anything i can do to draw attention to this? I've been struggling with it for a long time, and my code is repeated so many times. The biggest problem is that any time I make a change, I have to add/remove those lines in many different subs, and i am prone to missing things.

     

    Thank you in advance. I'm sorry if this question is stupid, but I don't know where else to look.

Children
No Data