command button color

  • Thread starter Thread starter mark kubicki
  • Start date Start date
M

mark kubicki

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
 
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.
 

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

Back
Top