PDA

View Full Version : Bar Chart Column Colors



demolay
12-18-2008, 02:25 AM
Hi,

I searched through forum but could not find an answer for the following question of mine: I need to change colors of columns in a bar chart.

Manually I do the following: Select chart, click edit chart object, select column 1, set color, select column 2, set color, select column 3, set color, then close edit chart object. What I need is: I will select chart, click macro and it will set different color for each column.

John Wilson
12-23-2008, 08:37 AM
See if this helps

Sub ograph()
Dim osld As Slide
Dim oshp As Shape
Dim ograph As Object
For Each osld In ActivePresentation.Slides
'Find the msGraph object
For Each oshp In osld.Shapes
If oshp.Type = msoEmbeddedOLEObject Then
If oshp.OLEFormat.ProgID Like "MSGraph*" Then
'it's a graph
Set ograph = oshp.OLEFormat.Object
'do something with it
ograph.SeriesCollection(1).Interior.Color = RGB(255, 0, 0) 'red
ograph.SeriesCollection(2).Interior.Color = RGB(0, 0, 255) 'blue
End If 'it's an OLE object
End If 'it's a graph

Next oshp
Next osld
End Sub

delvi
01-20-2009, 11:17 PM
Hi John,

Could you please help me out with a code which helps in changing the colours of only the active chart rather than changing the colours of all the charts present in the active slide of the PPT.

The above code changes the colours of all the charts present in the active slide.

Awaiting for a quick and positive response.
Thanks in advance
Delvi

John Wilson
01-21-2009, 05:45 AM
If you mean the selected graph maybe this will help

Dim osld As Slide
Dim oshp As Shape
Dim ograph As Object
Set osld = ActiveWindow.View.Slide
'Check the msGraph object
Set oshp = ActiveWindow.Selection.ShapeRange(1)
If oshp.Type = msoEmbeddedOLEObject Then
If oshp.OLEFormat.ProgID Like "MSGraph*" Then
'it's a graph
Set ograph = oshp.OLEFormat.Object
'do something with it
ograph.SeriesCollection(1).Interior.Color = RGB(255, 0, 0) 'red
ograph.SeriesCollection(2).Interior.Color = RGB(0, 0, 255) 'blue
End If 'it's an OLE object
End If 'it's a graph

demolay
01-21-2009, 06:51 AM
That is what I am looking for! This macro will save hours.

Thanks a lot :)

demolay
01-21-2009, 07:22 AM
I have a new problem related to this one: I cannot set any color I want. For example, when I put RGB(187, 224, 227) into code, chart color becomes a slightly different color. Original one is close to blue, what I get is close to grey.

Cosmo
01-21-2009, 08:30 AM
Charts are limited to a small pallete of colors, you don't have the entire RGB range available, so it's probably selecting the closest to the color you picked.

demolay
01-21-2009, 08:37 AM
Yes, that is what it does, selecing the closest color.
But when I set colors from master slide --> edit color scheme, it applies any color I want to charts. Why it fails with macro? Is there a way to set any RGB color I want with macro?