Log in

View Full Version : [SOLVED:] Changing fill colors in charts (selected data series)



RandomGerman
06-07-2016, 03:16 AM
Hello,

I've got a piece of code to change fill colors of shapes, table cells and even grouped objects selected by the user. But is it possible to make it work for data series or data points (selected by the user) in MS graph charts, too? And if yes: How? The actual code takes an MS graph charts as one object and fills it in total, not the selected data series or data point. I think, this is not a mistake, there is just some code missing, working for the data series in the chart.

Any help is appreciated. Thank you,
RG


Sub FillColor()
Dim oshp As Shape
Dim oTbl As Table
Dim x As Long
Dim y As Long
On Error GoTo err

If ActiveWindow.Selection.HasChildShapeRange Then
With ActiveWindow.Selection.ChildShapeRange.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
End With

Else
For Each oshp In ActiveWindow.Selection.ShapeRange
If ActiveWindow.Selection.ShapeRange(1).HasTable Then
Set oTbl = ActiveWindow.Selection.ShapeRange.Table
For x = 1 To oTbl.Rows.Count
For y = 1 To oTbl.Columns.Count
If oTbl.Cell(x, y).Selected Then
oTbl.Cell(x, y).Shape.Fill.Visible = msoTrue
oTbl.Cell(x, y).Shape.Fill.ForeColor.RGB = RGB(255, 0, 0)
End If
Next
Next
Else
oshp.Fill.Visible = msoTrue
oshp.Fill.ForeColor.RGB = RGB(255, 0, 0)
End If
Next oshp
End If

Exit Sub

err:
MsgBox "Select at least one shape"
End Sub

John Wilson
06-07-2016, 10:15 AM
The short answer is NO

This is a major failing in vba for charts in PowerPoint. It works in Excel but not in PPT

RandomGerman
06-08-2016, 04:31 AM
John, thank you very much for the clear and quick response.