【发布时间】:2020-07-11 06:25:06
【问题描述】:
您好,我正在尝试将许多图表表复制并粘贴到 PowerPoint 中,每个图表表都有自己的幻灯片。
此代码只会在工作表中获取图表,而不是图表。
我在网上找到了大部分代码并对其进行了修改,以便将图表作为 png 图像粘贴到幻灯片中。 我该如何更改它,以便我可以遍历所有图表并让它们过去进入 Excel。我也想从左图开始,从左到右循环。
Sub ExportChartsToPowerPoint_MultipleWorksheets()
' OVERVIEW:
' This script will loop through all the worksheets in the Active Workbook
' and copy all the Charts to a new PowerPoint presentation that we create.
' Each chart will get their own individual slide and will be placed in the center of it.
'Declare PowerPoint Variables
Dim PPTApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim PPTSlide As PowerPoint.Slide
Dim PPTShape As PowerPoint.Shape
Dim SldIndex As Integer
'Declare Excel Variables
Dim Chrt As ChartObject
Dim Chart As Chart
Dim WrkSht As Worksheet
'Create new PowerPoint Application & make it visible.
Set PPTApp = New PowerPoint.Application
PPTApp.Visible = True
'Create new presentation in the PowerPoint application.
Set pptPres = PPTApp.Presentations.Add
'Create an index handler for slide creation.
SldIndex = 1
For Each WrkSht In Worksheets
'Loop through all the CHARTOBJECTS in the ACTIVESHEET.
For Each Chrt In WrkSht.ChartObjects
'Copy the Chart
Chrt.Copy
'Create a new slide in the Presentation, set the layout to blank, and paste chart on to the newly added slide.
Set PPTSlide = pptPres.Slides.Add(SldIndex, ppLayoutBlank)
PPTSlide.Shapes.PasteSpecial DataType:=ppPastePNG
'Increment index so that way we paste the next chart on the new slide that is added.
SldIndex = SldIndex + 1
Next Chrt
Next WrkSht
End Sub
【问题讨论】:
-
这段代码有什么问题?如果有错误信息,它会出现在哪一行?
-
它不会复制和粘贴图表中的图表。它只适用于工作表中的图表。
标签: excel vba powerpoint