ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   command button color (https://www.excelbanter.com/excel-programming/306897-command-button-color.html)

Mark Kubicki

command button color
 
is there a way to refer to the color of the button as simply "red..." rather
than: &H8000000F& (it's a bit cryptic)

as always, thanks in advance



Bob Kilmer

command button color
 
If in VBA, use the pre-defined color constants or, if not available, define
your own.

Private Sub CommandButton1_MouseUp(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
If CommandButton1.BackColor < vbRed Then
CommandButton1.BackColor = vbRed
CommandButton1.ForeColor = vbBlack
Else
CommandButton1.BackColor = vbBlack
CommandButton1.ForeColor = vbRed
End If
End Sub

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

Const clrRed = &HFF&
Const clrBlack = &H80000012

If CommandButton1.BackColor < clrRed Then
CommandButton1.BackColor = clrRed
CommandButton1.ForeColor = clrBlack
Else
CommandButton1.BackColor = clrBlack
CommandButton1.ForeColor = clrRed
End If
End Sub

You can define constants in a procedure, or in the declaration section (at
the top) of a module, either private or public, depending on the scope (how
widely available among your code) that you need.

"mark kubicki" wrote in message
...
is there a way to refer to the color of the button as simply "red..."

rather
than: &H8000000F& (it's a bit cryptic)

as always, thanks in advance






All times are GMT +1. The time now is 08:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com