+ Reply to Thread
Results 1 to 3 of 3

Code to make buttons change colors on click

Hybrid View

  1. #1
    Registered User
    Join Date
    06-14-2012
    Location
    Ames, Iowa
    MS-Off Ver
    Excel 2010
    Posts
    50

    Code to make buttons change colors on click

    I am looking for help for code that when I click a button it says "RED" and also makes the button Red. Then when I click the button again, it displays "WHITE" and makes the button white. And then every time I click the button it just alternates back and forth between Red and White.

    Any help would be appreciated
    Thanks!

  2. #2
    Forum Contributor
    Join Date
    08-21-2008
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Office 2007
    Posts
    255

    Re: Code to make buttons change colors on click

    assign this macro to the button
    Option Explicit
    
    Sub BtnSwitch()
    '----------------------------------------------------------------------------------
    ' Author    : Wotadude
    ' Date      : 11-Jan-2013
    ' Purpose   : switch button colour state
    '----------------------------------------------------------------------------------
        
        With ActiveSheet.Shapes(Application.Caller)
            Select Case UCase(.TextFrame.Characters.Text)
                Case "RED"
                    ' if red now
                    .TextFrame.Characters.Text = "White"
                    .Fill.ForeColor.RGB = RGB(255, 255, 255) ' white fill
                    .TextFrame.Characters.Font.Color = RGB(255, 0, 0) ' red font
                Case Else
                    ' start with red
                    .TextFrame.Characters.Text = "Red"
                    .TextFrame.Characters.Font.Color = RGB(255, 255, 255) ' red fill
                    .Fill.ForeColor.RGB = RGB(255, 0, 0) ' white font
            End Select
        End With
    
    End Sub

  3. #3
    Registered User
    Join Date
    06-14-2012
    Location
    Ames, Iowa
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Code to make buttons change colors on click

    Wotadude,
    Thanks for your help. This is what I needed! I appreciate your time.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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