View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default How do I create a customized toolbar button? Excell 2007

If you know the start and end points of the text within the cell you can use VBA
to give different fonts, sizes and colors within a cell.

Sub CellFont()
With ActiveCell.Characters(Start:=1, Length:=5).Font
.ColorIndex = 3
.Bold = True
.Underline = True
.Size = 14
End With
With ActiveCell.Characters(Start:=6, Length:=3).Font
.Superscript = True
.ColorIndex = 5
End With
With ActiveCell.Characters(Start:=10, Length:=4).Font
.Bold = True
.Size = 18
.ColorIndex = 6
End With
End Sub

Bu, as Dave says, not by selecting a portion of the text within the cell.


Gord Dibben MS Excel MVP

On Fri, 13 Apr 2007 07:03:55 -0500, Dave Peterson
wrote:

First, if you meant that you wanted to run a macro agains just a portion of text
in the cell, then that's not possible. But you could change the font color and
strikethrough for the whole cell.

I recorded a macro when I did one cell:

Option Explicit
Sub Macro1()
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = True
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 3
End With
End Sub


Next I would edit it to keep just what I want:

Option Explicit
Sub Macro1()
With Selection.Font
.Strikethrough = True
.ColorIndex = 3
End With
End Sub

Then I'd give it a nice name:

Option Explicit
Sub RedAndStrikeThrough()
With Selection.Font
.Strikethrough = True
.ColorIndex = 3
End With
End Sub

Then back to excel.

Tools|macro|Macros...
Select that macro
click on Options
Give it a nice shortcut key combination

If you don't want the shortcut key, you can hit tools|macro|macros and select
your macro (hitting alt-f8 is a quick way to see that macro dialog).

And then test it out by selecting a range and hitting that shortcut key.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm



rllngriver wrote:

I would like to create button that would automatically change the format of a
cell's text or selected text to red with the strike through feature when I
clicked on it. How do I do that?