Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Powerpoint Automation - Charts Do Not Retain Data When Edited

Status
Not open for further replies.

ApocY85

Programmer
Dec 20, 2007
36
US
With the function of code displayed below, I am editing powerpoint charts to update them with the most current data from an excel document. Everything works perfect except for when a person starts to edit a chart, all the data values in the chart worksheet appear to be restored to their previous values. Is there a solution to this problem? It doesn't make sense why Powerpoint would save both the old values and the new, and suddenly revert to the older ones for no reason or with no warning.


Private Sub CopyExportData(ByVal excelFileLoc As String, ByVal slideNo As Integer, ByVal xStart As Integer, ByVal yStart As Integer, ByVal xEnd As Integer, ByVal yEnd As Integer, ByVal transpose As Boolean)
Dim excWB As Excel.Workbook
Dim chartHolder As PowerPoint.Shape
Dim chart As Graph.chart
Dim x, y As Integer

Set excWB = excApp.Workbooks.Open(excelFileLoc)
Set chartHolder = oPPTPres.Slides(slideNo).Shapes(2)
Set chart = chartHolder.OLEFormat.Object

With chart.Application.DataSheet
.Rows.Clear
.Columns.Clear

For x = xStart To xEnd
For y = yStart To yEnd
If transpose Then
.Cells(y, x).Value = excWB.Worksheets(1).Cells(x + 1, y)
Else
.Cells(x, y).Value = excWB.Worksheets(1).Cells(x + 1, y)
End If
Next
Next
End With

excWB.Close

Set chart = Nothing
Set chartHolder = Nothing
Set excWB = Nothing

End Sub

If anyone could help, I'd greatly appreciate it!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top