[英]Copying all charts from an Excel Sheet to a Powerpoint slide
I have built a workbook to facilitate the creation of a monthly report presentation I am in charge of. 我已经建立了一个工作簿,以方便创建我所负责的月度报告演示文稿。 The workbook has some data sheets, some processing sheets and then numbered sheets which contain the charts I need to paste to the corresponding slide.
该工作簿有一些数据表,一些处理表,然后是编号表,其中包含我需要粘贴到相应幻灯片的图表。 So far, I've built the VBA for opening the PowerPoint template and looping through each excel sheet, and discriminating which sheet names are numeric, and then activating the corresponding slide on the powerpoint template.
到目前为止,我已经建立了VBA,用于打开PowerPoint模板并遍历每个excel工作表,并区分哪些工作表名称为数字,然后激活PowerPoint模板上的相应幻灯片。
Unlike other solutions to similar problems I've found, I'd like to copy all charts from each numbered sheet to each slide at a time, as they are different in shape, quantities and disposition for each sheet/slide. 与发现类似问题的其他解决方案不同,我想一次将所有图表从每个编号的工作表复制到每个幻灯片,因为它们的形状,数量和放置方式各不相同。 I've mostly only found people copying one chart at a time and pastying as image, which will also not work for me (I need to fine tune data labels and position on the final slide).
我几乎只发现人们一次复制一张图表并粘贴为图像,这对我也不起作用(我需要微调数据标签和最后一张幻灯片上的位置)。 Any hints as to how could I achieve that?
关于如何实现这一点的任何提示?
Here's what my code looks like so far: 到目前为止,这是我的代码:
Sub CriarSlides()
Dim pptApp As Powerpoint.Application
Dim pptPres As Powerpoint.Presentation
Dim strFileToOpen As Variant
Dim strFileName As String, Hosp As String
Dim datawb As Workbook
Dim xlsCounter As Integer, xlsSlide As Integer
Set datawb = ThisWorkbook
strFileToOpen = Application.GetOpenFilename _
FileFilter:="Powerpoint Files *.pptx (*.pptx),")
If strFileToOpen = False Then
Exit Sub
Else
Set pptApp = New Powerpoint.Application
pptApp.Visible = True
pptApp.Presentations.Open Filename:=strFileToOpen, ReadOnly:=msoFalse, Untitled:=msoTrue
Set pptPres = pptApp.Presentations(1)
End If
For xlsCounter = datawb.Worksheets.Count To 1 Step -1
If IsNumeric(datawb.Worksheets(xlsCounter).Name) Then
xlsSlide = datawb.Worksheets(xlsCounter).Name
' This is the problematic part
Debug.Print xlsSlide
End If
Next xlsCounter
End Sub
With the following modified code you can paste the chart-objects of each sheet in the corresponding slide: 使用以下修改的代码,您可以将每个工作表的图表对象粘贴到相应的幻灯片中:
Sub CriarSlides()
Dim pptApp As PowerPoint.Application, pptPres As PowerPoint.Presentation
Dim strFileToOpen As Variant, sh As Worksheet, ch As ChartObject
strFileToOpen = Application.GetOpenFilename(FileFilter:="Powerpoint Files *.pptx (*.pptx),")
If strFileToOpen = False Then Exit Sub
Set pptApp = New PowerPoint.Application
pptApp.Visible = True
Set pptPres = pptApp.Presentations.Open(fileName:=strFileToOpen, ReadOnly:=msoFalse)
For Each sh In ThisWorkbook.Sheets
If IsNumeric(sh.name) Then
For Each ch In sh.ChartObjects
ch.Copy
With pptPres.Slides(CLng(sh.name)).Shapes.Paste
.Top = ch.Top
.Left = ch.Left
.Width = ch.Width
.Height = ch.Height
End With
Next
End If
Next
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.