excel - 如何通过 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
解决方案
例子:
代码:
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
结果:
推荐阅读
- python - CVXPY 中具有优化变量的块矩阵
- c - GCC 发出的标签不会被该标签之外的任何东西跳转到?
- javascript - 检查是否所有异步 http 请求都已完成
- python - 如何通过 Hamming 或 Levenshtein 距离对字符串进行聚类
- linux - 在错误的家中创建目录
- python - 通过线性评估进行迁移学习:SimCLR,高损失值(损失:28494.7827)
- python - 我可以在 R 中使用什么来导入行星镜图像以将其从辐射转换为反射
- reactjs - 消费者无法通过函数 prop 更新上下文
- javascript - 创建新元素 JS 的更有效方法(不知道标题应该叫什么)
- flutter - InAppWebView 有类似 onPageFinished 的方法吗?