View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Excel 2007 Chart colorindex?

See comments in-line -

"L_P" wrote in message

I've got something similar under pre-2007, but rather than assigning an
explicit color value to the bars in my graph, I'm taking the value from
a specific cell. (This allows the user to configure the graph's
appearance).

This code works (or has under the pre-2007 versions I've tried it on):


Code:
--------------------

With <path.SeriesCollection(SeriesName)
.Interior.Pattern = Target.Interior.Pattern
.Interior.PatternColorIndex = Target.Interior.PatternColorIndex
.Interior.ColorIndex = Target.Interior.ColorIndex
End With


In all versions "Pattern" is probably going to be wrong. There are different
'sets' of patterns for cells and chart formats, with many more available for
the latter.

If you really want to copy the pattern you'll need to make a lookup table of
what pattern to apply to the chart that's similar in appearence to the cell
pattern. Bit of experimantation to make the table




Here, SeriesName holds the name of the data series being changed, and
Target is the Range (from the Excel sheet) which holds the desired
format.

But this is not working under 2007.

There appear to be 2 problems:


1) It doesn't want to accept SeriesName as a valid selector for
SeriesCollection. When I replace the variable with the explicit string
it works fine (e.g. replace the variable SeriesName with "Series1"),
even when that explicit string is the exact value of the string
variable. Is there some new flag to add?


I can only assume something simple your end is going wrong here. Absolutely
no reason why the "text" works and yet the same in a string variable fails.


2) The color doesn't change properly.

Now, I assume this is because, under 2007, the graph's colors are being
computed from different fields - RGB, ForeColor, etc. (As suggested by
the examples above).

How do I, under 2007, pick up the "fill" information out of the Target
range (background color and pattern) and apply that to the Series in the
graph?


Although the 56 colour palette works in 2007 for compatibility, better for
what you're trying to do to use RGB colours, eg (sr refers to the series)

sr.Format.Fill.ForeColor.RGB = cell.Interior.Color

Before doing anything might want to ensure the series fill is solid, simply
sr.Format.Fill.Solid

Then if you want to apply a pattern (from the lookup table)
p = cell.Interior.Pattern
If p < 1 Or p < xlNone Or p < xlAutomatic then
get pattern-number from lookup using p then
sr.Fill.Patterned pattern-number
sr.Format.Fill.BackColor.RGB = cell.Interior.PatternColor

Note in Excel 2007 the cell's apparent fill colour might be from a Table
style of a conditional format - these will not be returned from the cell's
RGB format. Such a colour can be obtained but a lot more work.

Regards,
Peter T