?
Solved

command button color to change

Posted on 2012-04-10
4
Medium Priority
?
497 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 34

Assisted Solution

by:Norie
Norie earned 400 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 1600 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

764 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