Solved

command button color to change

Posted on 2012-04-10
4
491 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 42

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 42

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

733 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