selection.font.color returns wrong color; the first execution
I don't see how a dual palette can be used since changing the color of an
index immediately changes the color throughout the workbook. But, there is
a lot I don't know and can't imagine!
Now, this has become even more confusing the code below (much of it is
redundant) was executed in two ways, each with similar but different
results.
First it was executed in the Immediate Window; one step at a time. Both
ActiveWorkbook and ThisWorkbook were used. No change since the code
effectively resides in the ActiveWorkbook. The results we
16711680
32
255
255
255
(ActiveSheet.Select performed here)
16711680
16711680
Color Test
Then a new workbook was manually created, a module inserted, and the code
was copied to a subroutine. The Workbooks.Add code was commented out.
Before executing a second subroutine was created consisting of three lines
of code
Debug.Print ActiveSheet.Range("A1").Font.Color
ActiveSheet.Select
Debug.Print ActiveSheet.Range("A1").Font.Color
These lines of code exist within the first subroutine so I would think the
results would be the same.
The results we
First Routine, notice that the Font Color was reported as 255 (red) five
times in a row, unlike in the Immediate Window.
16711680
255
32
255
255
255
(ActiveSheet.Select performed here)
255
255
Color Test
Second Routine, oops.
16711680
255
(I'm sending the rest of my hair to Microsoft, but if they are not careful I
will send them my first born later. ;)
'=================== Start of code
'Start a new workbook being sure to start with the default colors and a
known worksheet.
Workbooks.Add Template:="Workbook"
ActiveWorkbook.ResetColors
Activeworkbook.Sheets(1).select
Activeworkbook.Sheets(1).activate
Activeworkbook.Sheets(1).Name = "Color Test"
'place the word Color in A1
ActiveSheet.Range("A1").value = "Color"
'Make the text of a size that color can be more readily seen.
Activesheet.Range("A1").Font.Size = 14
Activesheet.Range("A1").Font.Bold = True
'Change the font color of A1 to the color in index 32. The font is now
blue.
Activesheet.Range("A1").Font.ColorIndex = 32
'Report the Font Color in the cell (FF0000, or 16711680; ie Blue)
debug.Print Activesheet.Range("A1").Font.Color
'change the color of Index 32 to Red. The font is now red.
ActiveWorkbook.colors(32) = &HFF
'Report the ColorIndex value. (32)
debug.Print Activesheet.Range("A1").Font.ColorIndex
'Report the Color of the ColorIndex 32 (FF, ie Red)
debug.Print ActiveWorkbook.Colors(32)
'Report the Font Color in the cell (FF, or 255; ie Red.... huh?)
debug.Print Activesheet.Range("A1").Font.Color
'Report the Font Color in the cell again (FF, or 255; )
debug.Print Thisworkbook.WorkSheets("Color Test").Range("A1").Font.Color
'Now, select the ActiveSheet, just for fun
Activesheet.select
'Report the Font Color in the cell again (FF0000, or 16711680; )
debug.Print Activesheet.Range("A1").Font.Color
'Ok, what is the font color now?
debug.Print Thisworkbook.WorkSheets("Color Test").Range("A1").Font.Color
'Do a bit of testing
debug.Print Thisworkbook.ActiveSheet.name
'=================== End of code
--
My handle should tell you enough about me. I am not an MVP, expert, guru,
etc. but I do like to help.
"Peter T" <peter_t@discussions wrote in message
...
So what's the actual code you use.
#32 in a default palette is 100% blue.
It is possible to create a workbook that sustains two unique palettes
concurrently, one default and one customized, each viewable in different
windows of the same workbook. There's a bit of a knack to doing this (I
always forget!) and easy to loose the dual palette. Perhaps something
along
these lines is occurring for you.
Regards,
Peter T
"AnExpertNovice" wrote in message
...
No, but good point.
In this case the code resides in the current workbook so ActiveWorkbook
and
ThisWorkbook are the same.
Thanks for the thought.
A co-worker said he had a similar situation with Excel workbooks created
by
Business Objects. Opening the workbook allowed viewing the report but
trying to print or do a print preview generated an error. Clicking on
the
worksheet tab "fixed" the problem. Essentially they are maunally doing
an
Activeworksheet.Select to work around the issue.
|