首页 > 解决方案 > 如何通过 Excel VBA 修改 Powerpoint Chart ChartData

问题描述

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

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

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

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

标签: excelvbachartspowerpoint

解决方案


例子:

在此处输入图像描述

代码:

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

结果:

在此处输入图像描述


推荐阅读