PDA

View Full Version : Solved: RESOLVED: Change ufm command button color in VBA?



Remalay
07-28-2006, 12:48 AM
Guys,
I've managed to stumble over the means of changing the background colour of commandbuttons on a userform within VBA coding, but am struggling to determine the logic behind the colour grading.:banghead:

Can anyone advise?


Private Sub CommandButton1_Click()
With UserForm1
.cb1.BackColor = &HFFA080
.cb2.BackColor = &HFFA8C0
.cb3.BackColor = &HFFC000
.cb4.BackColor = &HFFD000
.cb5.BackColor = &HFF0000
.Show
End With
End Sub

Remalay
07-28-2006, 02:09 AM
With UserForm1
.cb1.BackColor = RGB(0,0,0) ' Black
.cb2.BackColor = RGB(255,0,0) ' Red
.cb3.BackColor = RGB(0,255,0) ' Green
.cb4.BackColor = RGB(0,0,255) ' Blue
.cb5.BackColor = RGB(255,255,255) ' White
.Show
End With

Killian
07-28-2006, 07:01 AM
HI and welcome to VBAX :hi:

The Backcolor property is a Long integer.
It can also be set by using the RGB() function (as in you second post) or using a Hex value (first post) or any other expression that returns a long value.