Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerPoint VBA - loop all slides, all shapes, find chart, set datalabel color to Black

I'm new to PowerPoint VBA so please bear with me.

I would like to:

  1. loop through all the slides on a given pptx,
  2. loop through all the shapes on a given slide,
  3. find chart shapes
  4. loop through the chart's series collection
  5. set the datalabel color property to dark black.

So far I have been able to complete the first 3 tasks but I need help with the last 2. Here is my code:

Sub test()

  Dim slide As Object
  Dim shape As Object
  Dim shapeNames As Object
  Dim chSeries As Series

  i = 0
  For Each slide In ActivePresentation.Slides

      For Each shape In slide.Shapes

          If shape.HasChart Then

              i = i + 1
              Debug.Print "found a chart on slide", i

          End If

      Next

  Next

End Sub
like image 584
Boosted_d16 Avatar asked Jul 24 '14 09:07

Boosted_d16


People also ask

How do you apply a shape to all slides PowerPoint?

On the View menu, point to Master, and then click Slide Master. On the Home tab, under Insert, click Shape, point to any shape type, and then click the shape that you want.


1 Answers

Solved.

Sub test()

    Dim sld As Slide
    Dim shp As Shape
    Dim sr As Series
    Dim chrt As Chart

        For Each sld In ActivePresentation.Slides
            For Each shp In sld.Shapes

                If shp.HasChart Then
                    Debug.Print shp.Chart.ChartType

                    If shp.Chart.ChartType = 57 Then

                        shp.Chart.SeriesCollection(1).DataLabels.Font.Color = RGB(0, 0, 0)

                     End If

                End If

    Next shp
    Next sld

End Sub

Though I didn't successfully loop over the series in chart but this works.

like image 107
Boosted_d16 Avatar answered Sep 19 '22 08:09

Boosted_d16