Solved

command button color to change

Posted on 2012-04-10
4
477 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now