PDA

View Full Version : Coloring Line Charts in PPT



magnel
04-16-2016, 05:55 AM
Hello,

I am using PPT 2010 and I am trying to put together a piece of code which colors only the selected line in the charts.
Here is the code which I am using:

Sub LineChart()
On Error Resume Next
With ActiveWindow.Selection.ShapeRange(1).Chart
.SeriesCollection(1).Format.Line.ForeColor.RGB = RGB(225, 215, 214)
.SeriesCollection(1).Format.Fill.ForeColor.RGB = RGB(225, 215, 214)
.SeriesCollection(2).Format.Line.ForeColor.RGB = RGB(231, 228, 223)
.SeriesCollection(2).Format.Fill.ForeColor.RGB = RGB(231, 228, 223)
.SeriesCollection(3).Format.Line.ForeColor.RGB = RGB(226, 233, 205)
.SeriesCollection(3).Format.Fill.ForeColor.RGB = RGB(226, 233, 205)
.SeriesCollection(4).Format.Line.ForeColor.RGB = RGB(240, 238, 217)
.SeriesCollection(4).Format.Fill.ForeColor.RGB = RGB(240, 238, 217)
End With
End Sub

This code colors all the Lines in the Line Chart, but I am not able to select a particular Line and color it.

Please can someone help me with some modification to the above code which will color only the selected line.

Thanks

John Wilson
04-18-2016, 07:05 AM
Unfortunately there is no way in PPt to change the selected series.

The only way is to read the ribbon to see which series is selected but this is extremely difficult using APIs and in my experience not reliable and only works in 32 bit.

There's no need to duplicate lines of code BTW I think this is the same

Sub LineChart()
On Error Resume Next
With ActiveWindow.Selection.ShapeRange(1).Chart
.SeriesCollection(1).Format.Line.ForeColor.RGB = RGB(225, 215, 214)
.SeriesCollection(2).Format.Line.ForeColor.RGB = RGB(231, 228, 223)
.SeriesCollection(3).Format.Line.ForeColor.RGB = RGB(226, 233, 205)
.SeriesCollection(4).Format.Line.ForeColor.RGB = RGB(240, 238, 217)
End With
End Sub

magnel
04-18-2016, 11:57 AM
Thank you so much John for your reply.

Had tried a lot to get a solution to it, but could not get through.

In case I get something will definitely post it here.