Foo_Man_Chu
Board Regular
- Joined
- Jul 22, 2010
- Messages
- 79
Hi all,
I'm trying to change the backcolor of a command button with the on click event of the button. Seeing that I will have several buttons to change the color or, I made a separate sub to change the button backcolor with that I can just call from the on click event of the button in question. Here's my code:
it should be pretty self explanatory and not that complex. However it's not behaving as I expect it to. Here's what's happening:
The button's backcolor is white and is clicked for the first time. It turns green.(Expected result) If I wait a second or two and click it again, it turns red. (Expected result). However, if I click it rapidly it takes 2 or 3 clicks to get it to turn red and 2 or 3 more clicks to turn it back to green(Not expected, it should only take one click to change back and forth between the colors).
I've looked for solutions for quite a while but no dice. I thought maybe for some reason the sub that changes the color was getting run more than once but I checked for that and I don't think that's the case. I thought that it might be another sub that was interfering so I deleted everything except these two subs and it still happens. Oh, I'm running Excel 2013 on Windows 10. And the button in question is an ActiveX command button.
Any help would be much appreciated. Thanks in advance.
I'm trying to change the backcolor of a command button with the on click event of the button. Seeing that I will have several buttons to change the color or, I made a separate sub to change the button backcolor with that I can just call from the on click event of the button in question. Here's my code:
Code:
Private Sub A3btn_Click()
ChangeButtonColor A3btn
End Sub
Private Sub ChangeButtonColor(strBtnName As CommandButton)
If strBtnName.BackColor = vbWhite Then 'white
strBtnName.BackColor = vbGreen 'green
ElseIf strBtnName.BackColor = vbGreen Then 'green
strBtnName.BackColor = vbRed 'red
ElseIf strBtnName.BackColor = vbRed Then 'red
strBtnName.BackColor = vbGreen 'green
End If
End Sub
it should be pretty self explanatory and not that complex. However it's not behaving as I expect it to. Here's what's happening:
The button's backcolor is white and is clicked for the first time. It turns green.(Expected result) If I wait a second or two and click it again, it turns red. (Expected result). However, if I click it rapidly it takes 2 or 3 clicks to get it to turn red and 2 or 3 more clicks to turn it back to green(Not expected, it should only take one click to change back and forth between the colors).
I've looked for solutions for quite a while but no dice. I thought maybe for some reason the sub that changes the color was getting run more than once but I checked for that and I don't think that's the case. I thought that it might be another sub that was interfering so I deleted everything except these two subs and it still happens. Oh, I'm running Excel 2013 on Windows 10. And the button in question is an ActiveX command button.
Any help would be much appreciated. Thanks in advance.