I want to change the range of my embedded chart in PowerPoint on Slide 2 (data in excel) from the Range (C2:F2) to the Range (C3:F3) and update the chart automatically.
Option Explicit
Sub ModifyChartData()
Dim WB As Workbook
Set WB = Workbooks.Open(FileName:="U:\Automatisierung\Auto.xlsx", ReadOnly:=True)
With ActivePresentation.Slides(2).Shapes("Chart 1").Chart.ChartData
.Activate
WB.Sheets("Chart").Range("B2").Value = WB.Sheets(2).Range("B3").Value
WB.Sheets("Chart").Range("C2").Value = WB.Sheets(2).Range("C3").Value
WB.Sheets("Chart").Range("D2").Value = WB.Sheets(2).Range("D3").Value
WB.Sheets("Chart").Range("F2").Value = WB.Sheets(2).Range("F3").Value
WB.Close SaveChanges:=True
End With
End Sub
EDIT: I have updated the code and the value are now being changed from B2 --> B3 etc. I have now the problem with the workbook: I want that the chart is updated and the workbook closes again. For: WB.Close SaveChanges:=True --> It wants to save the file a new. WB.Close SaveChanges:=False --> I lose the updated chart.
How can I save and update the file within the macro?
Thanks a lot!