JRaanaas
JRaanaas

Reputation: 31

Setting the color of AutoShapeType within a chart in PowerPoint

I need to change the colors of autoshapetypes which are connected to datalabels within a chart.

I have this code to format the chart but i cant find the code to change the autoshapetype color.

Sub Format_linechart_smoothlines()

    Dim sld As Slide
    Dim shp As Shape
    Dim chart As chart
    Dim sr As Series
    Dim i As Long
    
    Set sld = Application.ActiveWindow.View.Slide
    
    For Each shp In sld.Shapes
        If shp.HasChart Then
            Set chart = shp.chart
            For i = 1 To chart.SeriesCollection.Count
                Set sr = chart.SeriesCollection(i)
                sr.Smooth = True
                sr.Format.Line.Weight = 3
                sr.HasDataLabels = True
                sr.DataLabels.Position = xlLabelPositionCenter
                sr.DataLabels.Font.Color = RGB(255, 255, 255)
                sr.DataLabels.Font.Size = 10
                sr.DataLabels.Format.AutoShapeType = msoShapeRectangle
            Next i
        End If
    Next shp
End Sub

I've also tried to change the color of the shape in a different macro but it doesn't change the colors of the shapes within the chart:

Sub ChangeRectangleShapes_Color()

    Dim sld As Slide
    Dim shp As Shape
    
    Set sld = Application.ActiveWindow.View.Slide

    For Each shp In sld.Shapes
      If shp.AutoShapeType = msoShapeRectangle Then
        shp.Fill.ForeColor.RGB = RGB(0, 0, 0)
      End If
  Next shp

End Sub

Upvotes: 0

Views: 50

Answers (1)

Domenic
Domenic

Reputation: 8114

To set the fill color for your data labels, try...

sr.DataLabels.Format.Fill.ForeColor.RGB = RGB(255, 0, 0)

Change the color as desired.

Upvotes: 1

Related Questions