ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Font color buttons? (https://www.excelbanter.com/excel-programming/291126-font-color-buttons.html)

HONYAKUKA

Font color buttons?
 
Excel2000

The font color toolbar button works to change (A) an entire cell (or selection
of cells), or (B) selected text within a cell.

I'd like to create a couple of custom buttons, one for red text, one for black
etc., etc. The code for (A) is relatively straightforward. The code for (B)
is a mess, at least if you try to record a macro.

Anyway, as a first step, how would you distinguish in VBA between "cell or
range is selected" and "cell contents are selected"?

Then, how do you generalize (B) such that the code changes the color of
whatever text happens to be selected?

Thanks very much.

Jay


Barry Pettis[_2_]

Font color buttons?
 
As far as I know it is not possible to execute a macro
when you have text highlighted in the formula bar. So I'm
thinking that your part B will not be possible.



-----Original Message-----
Excel2000

The font color toolbar button works to change (A) an

entire cell (or selection
of cells), or (B) selected text within a cell.

I'd like to create a couple of custom buttons, one for

red text, one for black
etc., etc. The code for (A) is relatively

straightforward. The code for (B)
is a mess, at least if you try to record a macro.

Anyway, as a first step, how would you distinguish in VBA

between "cell or
range is selected" and "cell contents are selected"?

Then, how do you generalize (B) such that the code

changes the color of
whatever text happens to be selected?

Thanks very much.

Jay

.


HONYAKUKA

Font color buttons?
 
I think you're basically correct, although why it should be this way is not
clear.

Here's an interesting experiement. Create a simple macro like the following in
Personal.xls:

Sub FontColorRed()
Selection.Font.ColorIndex = 3
End Sub


In a new workbook, type a word into a cell. Reduce the Excel window and the
VBA window (the one containing the above macro) so that each covers half the
screen. Put the cursor into the above macro in the VBA window. Back in the
workbook, select some of the letters in the word that you just typed. Click
the VBA icon on the taskbar (thus forcing the VBA window to be in the
forefront; you can't do this with Alt-Tab once part of a cell is selected) and
press F5, to force the macro to run. The selected letters will turn red.

Is there really no other way to invoke this process?

Jay


As far as I know it is not possible to execute a macro
when you have text highlighted in the formula bar. So I'm
thinking that your part B will not be possible.



-----Original Message-----
Excel2000

The font color toolbar button works to change (A) an

entire cell (or selection
of cells), or (B) selected text within a cell.

I'd like to create a couple of custom buttons, one for

red text, one for black
etc., etc. The code for (A) is relatively

straightforward. The code for (B)
is a mess, at least if you try to record a macro.

Anyway, as a first step, how would you distinguish in VBA

between "cell or
range is selected" and "cell contents are selected"?

Then, how do you generalize (B) such that the code

changes the color of
whatever text happens to be selected?

Thanks very much.

Jay

.












All times are GMT +1. The time now is 11:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com