How do I set the BackColor property of an Activex Command Button using colorindex

KentBurel

Board Regular
Joined
Mar 27, 2020
Messages
68
Office Version
  1. 2019
Platform
  1. Windows
I'm building a simple test case to understand how to set the BackColor property of an ActiveX Command button to one of the 56 colorindex colors. I can get it to work with the RGB function. My code looks like this:
VBA Code:
Sub ControlColor()
    Dim myColorindex As Integer
    Dim i As Integer
    Dim response As String
   
    For i = 1 To 56
        Worksheets("Sheet1").Label1.BackColor = RGB(0, 0, 255)
        response = MsgBox("Continue?", vbOKOnly, " ")
    Next i
End Sub

How do I do the same thing using ColorIndex numbers?

Or how do I convert ColorIndex numbers to RGB values?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Change RGB(0, 0, 255) to this :

VBA Code:
Worksheets("Sheet1").Label1.BackColor = ActiveWorkbook.Colors(i)
 
Upvote 0
Wow. Works perfectly. Of course this is just a learning exercise. But now I know how to incorporate it into my real project. Thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,901
Members
449,097
Latest member
dbomb1414

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