+ Reply to Thread
Results 1 to 3 of 3

change button colour when clicked

Hybrid View

  1. #1
    Registered User
    Join Date
    03-01-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2010
    Posts
    64

    change button colour when clicked

    Hello people

    This follows on from a previous post about changing the text in a button when clicked, my code now looks like this:

    Sub Button16_Click()
    
        Dim strCap As String
    
        With Columns("M:R").EntireColumn
            .Hidden = Not .Hidden
            If .Hidden Then
                strCap = "Show R&R"
            Else
                strCap = "Hide R&R"
            End If
        End With
    
    ActiveSheet.Buttons(Application.Caller).Caption = strCap
    
    End Sub
    What I want to now do is change the colour of the button to green when it displays the 'Hide R&R' option (when it says 'Show R&R' the colour can stay the same standard grey). How do I do this? Can anyone help please?

    Thanks
    Kenny
    Last edited by arlu1201; 12-14-2012 at 02:46 AM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: change button colour when clicked

    I think the type of button you are using is from the Form control toolbar as opposed to an ActiveX-type command button from the Control Toolbox toolbar.
    Overview of forms, form controls, and ActiveX controls on a worksheet

    I don't think that type of button control has a background color property. It does have a font color property if that helps.

    Sub Button16_Click()
        
        Dim btn   As Button
        Set btn = ActiveSheet.Buttons(Application.Caller)
        
        With Columns("M:R")
            .Hidden = Not .Hidden
            If .Hidden Then
                btn.Caption = "Show R&R"
                btn.Font.Color = RGB(0, 128, 0) 'Green
            Else
                btn.Caption = "Hide R&R"
                btn.Font.Color = vbBlack
            End If
        End With
        
    End Sub

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: change button colour when clicked

    Bonnister,

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1