0

I am working on a personal powerpoint project and I thought it would be cool to use activex in the powerpoint to make the slides a bit more interactive. I have some activex boxes where you can set a population and an annual growth rate and the final step would be for me to plot the 5 year projection data i am getting on a line graph. I have tried it using excel based VBA but most solutions seem to require pulling data from a sheet so won't work in powerpoint.

I have also tried the following code to build a chart skipping the need for a worksheet but to no avail as I get a runtime error 424: Object required error:

Sub AddChart()

    Dim cht     As Chart
    Dim ser     As Series

    Set cht = Charts.Add
    cht.ChartType = xlColumnClustered
    Set ser = cht.SeriesCollection.NewSeries
    ser.XValues = Array(1, 3, 5, 7, 9)
    ser.Values = Array(2.4, 3.2, 5.7, 12.67)

End Sub

Any solutions in mind or am I flogging a dead horse here?

Thanks!

0

2 Answers 2

1

Powerpoint doesn't have Charts.Add, but Shapes.AddChart2 or .AddChart

Something like this should get you going:

Sub AddChart()
    Dim cht As Chart
    Dim ser As Series

    Set cht = ActivePresentation.Slides(1).Shapes.AddChart(-1, xlColumnClustered).Chart
    Set ser = cht.SeriesCollection.NewSeries

    ser.XValues = Array(1, 3, 5, 7, 9)
    ser.Values = Array(2.4, 3.2, 5.7, 12.67)
End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

This solution works! Thanks, as you mentioned I was using the wrong operators. This solution still pops up an excel however and I was hoping to bypass that or perhaps at least use a screen updating false work around, do you have an idea of how to not rely on excel and keep it powerpoint only?
I don't know of any chart in Powerpoint that doesn't rely on Excel. That said, maybe you are looking for something like this - where the chart appearance is changed with an ActiveX button.
0

I know this is an old thread but in case someone stumbles on it like I did - you can paste an empty chart on a Master Layout and then copy it to any slide you need it on, that way Excel never launches to 'create' the chart object, although it is still 'embedded'.

If you create a special layout for it, just be sure to include a Title or some other placeholder because slides with no placeholders get helpfully removed/left behind by PowerPoint during certain operations - such as copying a slide into a new presentation and selecting 'Keep Source Formatting'.

1 Comment

The question was asking to use VBA only, this should be a workaround in a comment instead of posting as a solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.