+ Reply to Thread
Results 1 to 6 of 6

How to set text color of a button

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    10-05-2014
    Location
    Regina, SK Canada
    MS-Off Ver
    Excel for Mac 11
    Posts
    330

    How to set text color of a button

    I have a few buttons on an Excel worksheet that I want to change colour (black / red ) depending on a code. The goal of my routine is to make all 5 buttons black first and then make a selected one red.

    Here is the the subprogram that I made using code that was recorded when I manually changed the colour of a button. Unfortunately, there no instruction to change the text colour was recorded. All help would be greatly appreciated.

    Sub make1RedBtn(btnName As String, code As Integer)
        Dim newStyle As String
        Dim newColour As Integer
        Dim newSize As Integer
        
        If code = 0 Then
            newStyle = "Regular"
            newSize = 11
            newColour = 0     ' Black?
         Else
            newStyle = "Bold"
             newSize = 12
           newColour = 3    ' Red?
        End If
        
        ActiveSheet.Shapes.Range(Array(btnName)).Select
        With Selection.Characters(Start:=1, Length:=3).Font     ' all buttons have 3 chars
            .FontStyle = newStyle
            .Size = newSize
            .ColorIndex = newColour         ' <==== This line does not seem to work for me.
            End With
    End Sub

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,962

    Re: How to set text color of a button

    ActiveSheet.CommandButton1.BackColor = vbRed
    Ben Van Johnson

  3. #3
    Valued Forum Contributor
    Join Date
    10-05-2014
    Location
    Regina, SK Canada
    MS-Off Ver
    Excel for Mac 11
    Posts
    330

    Re: How to set text color of a button

    Thanks ProtonLeah. I think you misunderstood my request; your suggestion i suspect works with a command buttons on a user form. I will use that idea in the future I'm sure.

    However, what I want to do is change the text colour of a regular button on the Excel sheet.
    Any suggestions for that.

    - Stu

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,697

    Re: How to set text color of a button

    @StuCram
    Have you tried protonLeah's code with an ActiveX Button on your Sheet?
    Change BackColor To ForeColor for the Caption color
    Last edited by jolivanes; 03-02-2015 at 02:11 AM.

  5. #5
    Valued Forum Contributor
    Join Date
    10-05-2014
    Location
    Regina, SK Canada
    MS-Off Ver
    Excel for Mac 11
    Posts
    330

    Re: How to set text color of a button

    Nope. I'n not using ActiveX since it's available only on Windows and I need Mac compatibility.
    The suggested code did not work on a regular button on the Excel sheet when I tried it.
    Thanks for the suggestion.

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,697

    Re: How to set text color of a button

    Oh, a Mac.
    Did not see that Stu
    Sorry about that.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] change button text color
    By Martin Just in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-29-2015, 12:42 PM
  2. Change the text color of a form button in Excel Mac 2011?!
    By RiTz21 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-09-2014, 06:25 PM
  3. [SOLVED] Editing color/msoGradiant of shapes, option button and text boxes
    By MD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-23-2006, 01:10 PM
  4. Button or key to conditionally change text foreground color?
    By Kurt Swanson in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 02-27-2006, 05:45 PM
  5. [SOLVED] toggle button text color
    By John Davies in forum Excel General
    Replies: 5
    Last Post: 12-12-2005, 02:43 PM

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