Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Dallas, Texas, USA
    Posts
    1,680
    Thanks
    0
    Thanked 1 Time in 1 Post

    Making a 'textformat' button. (XL XP)

    In a follow up to the <!post=post about "color command buttons",331970>post about "color command buttons"<!/post> , can someone give an example of the code that would be attached to the buttons shown below that would yield the desired results?

    I think it would be neat to be able to select a cell (or range) and click one button that would apply the appropriate formatting, i.e. bold, white text on navy background...
    - Ricky

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Making a 'textformat' button. (XL XP)

    To cover your last example , i.e. bold, white text on navy background use something like : <pre> With Selection
    .Interior.ColorIndex = 11
    With .Font
    .ColorIndex = 2
    .Bold = True
    End With
    End With</pre>


    Andrew

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Making a 'textformat' button. (XL XP)

    There is no way to modify the color of a toolbar button in code; the only thing you could do is create a collection of buttons with all possible combinations of text color, background color and text style.

    Or are you asking for code that applies these properties to the selected cells? It would look like this:

    Sub BoldRedOnYellow()
    With Selection.Interior
    .ColorIndex = 6
    .Pattern = xlSolid
    End With
    With Selection.Font
    .ColorIndex = 3
    .Italic = False
    .Bold = True
    End With
    End Sub

    Instead of ColorIndex, you can also use Color, for example .Color = vbRed or .Color = RGB(128, 0, 128)

  4. #4
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Making a 'textformat' button. (XL XP)

    Hans and Andrew already provided some code.
    A Tip:
    A good way to learn this coding and the VB objects, is to record a macro that does the formatting. Look at the macro code and it becomes more obvious what it does. It just a matter of a few edits to "generalize" and to "clean it up" (get rid of all the select this, select that "crap")

    Steve

  5. #5
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Dallas, Texas, USA
    Posts
    1,680
    Thanks
    0
    Thanked 1 Time in 1 Post

    Thank You

    Thanks to each of you who responded. There always seems to be two or three formatting combinations that I use more than others. Just thought it would be nifty to have those combinations set to buttons on the toolbar. The "icon" buttons in my example were merely to indicate what the result would look like. It's not every instance when you can tell what an Excel button does just from looking at it!
    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    - Ricky

Posting Permissions

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