Solved

command button color to change

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

828 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