Changing the colour of a control button in Excel

Z

Zakynthos

What VB script is needed to, say, change the colour of a control button say
from gray to red when it is clicked.

I've tried using the scripts given in:

http://www.mrexcel.com/archive/Controls/5034.html

but nothing is happening when the button is clicked - if I format it as grey
and click it, then it stays gray, if I format it as red and click it, it
stays red. I would like it to change to red when clicked and remain gray
when not clicked - it must be possible!

many thanks
 
J

jeff.j.griffith

In the Click event for your button, you can include code like this:

If CommandButton1.BackColor = vbRed Then
CommandButton1.BackColor = vbButtonFace
Else
CommandButton1.BackColor = vbRed
End If
 
P

Peter T

I'm not quite sure what you want to do, perhaps this -

Private Sub CommandButton1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

CommandButton1.BackColor = vbRed
End Sub

Private Sub CommandButton1_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

CommandButton1.BackColor = vbButtonFace
End Sub

You might need similar KeyDown & KeyUp events. Normal code can go in either
the Down or Up events. Hope you'll choose a less forcefull colour than Red.

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top