Change the colour of a commanbutton with mouse hover

svmac

Board Regular
Joined
Feb 16, 2002
Messages
182
Hello all,

Is it possible to change the colour of a command button when the user hovers over the button with the mouse pointer?

I would like it to change from the default 'grey' to a blue on hover.

Thanks in advance
Stuart
 
svmac said:
Hello all,

Is it possible to change the colour of a command button when the user hovers over the button with the mouse pointer?

I would like it to change from the default 'grey' to a blue on hover.

Thanks in advance
Stuart

Hello Stuart,

To change the color is not a problem but what do you want to happen when the mouse hovers "outside" the button again, should it revert to the default grey again or should it remain blue ?

Ciao,

Don.
 
Upvote 0
Thanks for the quick reply Don.

Sorry for not clarifying - I am hoping for the button to return to it's original state after hovering away.

Thanks again
Stuart
 
Upvote 0
Hello again Stuart,

As I stated before, it is not a problem to change the color when the mouse hovers over the button:


Code:
Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)

CommandButton1.BackColor = vbBlue

End Sub

Unfortunately the MouseMove event is only fired when cursor is hovering over the button,
there is no event fired when the cursor moves off the button so I see no way to revert back to the
original color without using another event - This would mean that the user would have to do something
(like selecting a cell for example) before the color would revert back.

I'm looking into it and I'll get back if I find a solution !

Ciao,

Don.
 
Upvote 0
If CommandButton1 is on a UserForm, to revert the Backcolor use this ...

Code:
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    CommandButton1.BackColor = Me.BackColor
End Sub
 
Upvote 0
Thanks guys for the replies.

I want the button to hold its color until another button is hovered, so I can use the mousemove properties of the other button to change the color back at that point. I can work that code out for myself, so we can consider this one closed from my perspective!

Thanks again for all assistance.

Stuart
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top