Solved

command button color to change

Posted on 2012-04-10
4
483 Views
Last Modified: 2012-04-10
Hello All,

How can the color of a button changed/ like I click on the button THIS, and it changes colors to whatever I assign? Further, I tried to change the color here but its throwing errors..
Further, is a there a full list of color codes (if you can provide) that I can use to change on the command buttons?

Thanks
R
command-button-color-change.xlsm
0
Comment
Question by:Rayne
  • 2
4 Comments
 
LVL 41

Expert Comment

by:dlmille
ID: 37830254
I don't think you can change the color of a MSForms command button, however, you CAN insert a shape, then assign a macro to that, and certainly you can change a shape's interior color.

If you use an ActiveX command button, you can change the back color.

See tip here:
http://www.mrexcel.com/archive/Controls/5034.html

Dave
0
 
LVL 33

Assisted Solution

by:Norie
Norie earned 100 total points
ID: 37830300
As far as I know you can't change the colour of a Forms command button, which is what you have on the worksheet.

If it was an ActiveX command button you could use this in the sheet module.
CommandButton1.BackColor = vbCyan

Open in new window

There is a list of constants like vbCyan, you'll find it in the Object Browser(F2) if you search for ColorConstants.
0
 
LVL 41

Accepted Solution

by:
dlmille earned 400 total points
ID: 37830305
See attached example with a Shape being used as a command button, with clicks toggling between grey and cyan.  Code in a public module:

Sub This_Click()
Dim wkb As Workbook
Dim wks As Worksheet

    Set wkb = ThisWorkbook
    Set wks = wkb.ActiveSheet
    
    With wks.Shapes("MYButton")
        If .Fill.ForeColor.RGB = vbCyan Then
            .Fill.BackColor.RGB = 15921906 'grey
            .Fill.ForeColor.RGB = 15921906 'grey
        Else
            .Fill.BackColor.RGB = vbCyan
            .Fill.ForeColor.RGB = vbCyan
        End If
    End With
End Sub

Open in new window


And, in the Sheet1 codepage, we have the CommandButton1 click event, pretty much doing the same thing:

Private Sub CommandButton1_Click()

    If CommandButton1.BackColor = &H8000000F Then  'default color
        CommandButton1.BackColor = vbCyan
    Else
        CommandButton1.BackColor = &H8000000F
    End If
End Sub

Open in new window


Dave
command-button-color-change-r1.xlsm
0
 

Author Comment

by:Rayne
ID: 37830404
Hello Dave & Imnorie,

Thanks you guys for the quick help on this and demonstrating this aspect.

-R
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question