darkdog
darkdog

Reputation: 3995

Edit Powerpoint Chart Data via VBA Script

i've a powerpoint presentation with a chart which contains data from an excel table.

I would like to edit this data via the powerpoint VBA editor..

how can i do this? i cant find a way to access the data of the excel table.

greets

Upvotes: 0

Views: 10714

Answers (1)

Dr. belisarius
Dr. belisarius

Reputation: 61016

This code allows you to access an Excel WorkSheet embedded into a PowerPoint presentation.

Sub a()

Dim oSl As PowerPoint.Slide
Dim oSh As PowerPoint.Shape

Set oSl = ActivePresentation.Slides(1)

Set oSh = oSl.Shapes(1)

With oSh.OLEFormat.Object.Sheets(1)
    .Range("A1").Value = .Range("A1").Value + 1
    .Range("A2").Value = .Range("A2").Value - 1
End With

Set oSl = Nothing
Set oSh = Nothing

End Sub  

If the graph is linked to the data you modify, probably it'll update automagically. If not, force a re-calc.

HTH!

Edit

With the following change it works in Office 2007:

With oSh.OLEFormat.Object.WorkSheets(1)
    .Range("A1").Value = .Range("A1").Value + 1
    .Range("A2").Value = .Range("A2").Value - 1
End With

Upvotes: 3

Related Questions