Rejje
New Member
- Joined
- Jun 12, 2011
- Messages
- 15
Hi!
I'm trying to make the font color of the selected range within a worksheet temporarily change to a specific rgb. When not selected THEN change back to original font color setting.
However I'm not very successful...
Paste these codes into worksheet event while having another worksheet activated.
I've have started with below code. This changes the cell color, not the font color. It works allthough not without some possibilities of imrovement.
This is what I've tried for making font color temp change. Note there's no need for the workaround for no fill with font color (I think at least).
Does anyone have a clue of how to get this to work?
I'm trying to make the font color of the selected range within a worksheet temporarily change to a specific rgb. When not selected THEN change back to original font color setting.
However I'm not very successful...
Paste these codes into worksheet event while having another worksheet activated.
I've have started with below code. This changes the cell color, not the font color. It works allthough not without some possibilities of imrovement.
Code:
[LEFT][COLOR=blue]Const[/COLOR] activeFill [COLOR=blue]As[/COLOR] [COLOR=blue]Long[/COLOR] = 255 [COLOR=darkgreen]'<--Use sub 'a' below to find the right value for your color of choice.[/COLOR]
[COLOR=blue]Dim[/COLOR] oldCell [COLOR=blue]As[/COLOR] Range
[COLOR=blue]Dim[/COLOR] oldCellFill [COLOR=blue]As[/COLOR] [COLOR=blue]Long[/COLOR]
[COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] Worksheet_Activate()
[COLOR=blue]Set[/COLOR] oldCell = Selection
oldCellFill = Selection.Interior.Color
Selection.Interior.Color = activeFill
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] Worksheet_Deactivate()
[COLOR=blue]If[/COLOR] oldCellFill = 16777215 [COLOR=blue]Then[/COLOR] [COLOR=darkgreen]'<--Workaround for no fill[/COLOR]
oldCell.Interior.ColorIndex = 0
[COLOR=blue]Else[/COLOR]
oldCell.Interior.Color = oldCellFill
[COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
[COLOR=blue]Set[/COLOR] oldCell = [COLOR=blue]Nothing[/COLOR]
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] Worksheet_SelectionChange([COLOR=blue]ByVal[/COLOR] Target [COLOR=blue]As[/COLOR] Range)
[COLOR=blue]If[/COLOR] oldCellFill = 16777215 [COLOR=blue]Then[/COLOR]
oldCell.Interior.ColorIndex = 0
[COLOR=blue]Else[/COLOR]
oldCell.Interior.Color = oldCellFill
[COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
[COLOR=blue]Set[/COLOR] oldCell = Target
oldCellFill = Target.Interior.Color
Target.Interior.Color = activeFill
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Sub[/COLOR] a()
[COLOR=blue]Debug.Print[/COLOR] RGB(256, 0, 0)
[COLOR=blue]End Sub[/COLOR] [/LEFT]
This is what I've tried for making font color temp change. Note there's no need for the workaround for no fill with font color (I think at least).
Code:
Const activeFontThemeColor As Long = -16776961 '<--Use sub 'a' below to find the right value for your color of choice.
Dim oldCell As Range
Dim oldCellFontThemeColor As Long
Private Sub Worksheet_Activate()
Set oldCell = Selection
oldCellFontThemeColor = Selection.Font.ThemeColor
Selection.Font.ThemeColor = activeFontThemeColor
End Sub
Private Sub Worksheet_Deactivate()
oldCell.Font.ThemeColor = oldCellFontThemeColor
Set oldCell = Nothing
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set oldCell = Target
oldCell.Font.ThemeColor = oldCellFontThemeColor
oldCellFontThemeColor = Target.Font.ThemeColor
Target.Font.ThemeColor = activeFontThemeColor
End Sub
Sub a()
Debug.Print RGB(256, 0, 0)
End Sub
Does anyone have a clue of how to get this to work?