如何通过Excel VBA修改Powerpoint图表ChartData

时间:2019-04-03 08:13:41

标签: excel vba charts powerpoint

我正在尝试使用Excel-VBA在Powerpoint中修改ChartData(值)。 ChartData未链接到其他Excel工作簿。

检查: -PowerPoint已打开 -必需的演示文稿已打开 -图表位于幻灯片4

行为: -图表标题更改 -带有ChartData的工作簿打开 -运行时错误'424':需要Objeckt -调试标记以下行:

Chart.ChartData.Workbook.Worksheets("Tabelle1").Range("B2:B5").Value = 50

希望有人可以帮助我...:-)

Sub ModifyChartData()

Dim pptApp As Object
Dim pptPres As Presentation

Set pptApp = GetObject(, "PowerPoint.Application")
Set pptPres = pptApp.ActivePresentation


pptPres.Slides(4).Shapes("Diagramm1").Chart.ChartTitle.Text = "Sales Overview"
pptPres.Slides(4).Shapes("Diagramm1").Chart.ChartData.Activate
Chart.ChartData.Workbook.Worksheets("Tabelle1").Range("B2:B5").Value = 50
Workbooks.Close

End Sub

1 个答案:

答案 0 :(得分:1)

示例:

enter image description here

代码:

Set pptApp = GetObject(, "PowerPoint.Application")
Set pptPres = pptApp.ActivePresentation
pptPres.Slides(1).Shapes(1).Chart.ChartTitle.Text = "Sales Overview"
pptPres.Slides(1).Shapes(1).Chart.ChartData.Activate
pptPres.Slides(1).Shapes(1).Chart.ChartData.Workbook.Worksheets("Blad1").Range("B2:B5").Value = 50

结果:

enter image description here