How do I change the color of a command button in Excel?
I have the following two lines of code in a subroutine
fmNode.but_nodenext.BackColor = RGB(0, 0, 100)
I have a command button that I want changed to a color
whenever the focus is shifted to the Next commmand button
Any ideas. Thanks in advance.
If you want the command buttons to change color
when they have the focus then you need to look
@ the Enter & Exit events for tha commandbuttons.
1) 3 commandbuttons
2) commandbuttons are named
CommandButton1 - 3
If you have named your commandbuttons
then you will have to change the routine
using a select case and the name of your
3) The Enter & Exit is similar to the HasFocus
& LostFocus for a ActiveX object....the events
you would need for this.
Private Sub CommandButton1_Enter()
Private Sub CommandButton1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Private Sub CommandButton2_Enter()
Private Sub CommandButton2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Private Sub CommandButton3_Enter()
Private Sub CommandButton3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Private Sub ChangeBtnColor()
Dim obj As Object
Set obj = UserForm1.ActiveControl
If obj.Name Like "Comm*" Then 'Is it a commandbutton
If obj.BackColor = &HFF& Then 'Is it Red
obj.BackColor = &H8000000F 'Change to default color
obj.BackColor = &HFF& 'Change to Red
Set obj = Nothing