[英]Export Excel charts as pictures to PowerPoint
我在 excel 工作簿中,每张一张图表和多张图表,我正在尝试将所有图表作为图片导出到 PowerPoints 问题是我拥有的当前代码不起作用
Sub TEST_ExportChartsToPowerPoint_SingleWorkbook()
'Declare PowerPoint Object Variables
Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide
Dim SldIndex As Integer
'Declare Excel Object Variables
Dim Chrt As ChartObject
'Dim Chrt As ChartArea
Dim WrkSht As Worksheet
'Create a new instance of PowerPoint
Set pptApp = New PowerPoint.Application
pptApp.Visible = True
'Create a new Presentation within the PowerPoint Application
Set pptPres = pptApp.Presentations.Add
'Create an index handler for the slide creation
SldIndex = 1
'Loop through all of the worksheets in the active work book
For Each WrkSht In Worksheets
'WrkSht.Select
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
'Create a new slide, set the layout to blank, and paste the chart on the slide
Set pptSlide = pptPres.Slides.Add(SldIndex, ppLayoutBlank)
pptSlide.Shapes.Paste
'Increment our slide index
SldIndex = SldIndex + 1
Next WrkSht
End Sub
一个问题是您设置了With
语句,但您从未使用过它。 ActiveChart
是Workbook
object 的属性,它是代码中的变量WrkSht
。 将这些行更改为具有.
在他们面前。
改变这两行
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
至
.ActiveChart.ChartArea.Select
.ActiveChart.ChartArea.Copy
在您的With
块中。
无法保证这是您的代码的(唯一)问题,因为您没有告诉我们发生了什么错误,或者您的代码如何没有给您预期的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.