简体   繁体   English

将所有图表从Excel工作表复制到Powerpoint幻灯片

[英]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.

相关问题 从Excel到Powerpoint的VBA复制和粘贴图表 - VBA copying and pasting charts from excel to powerpoint 将 excel 中的所有图表复制到现有的 powerpoint 中 - Copy all charts from excel into an existing powerpoint 使用VBA在excel中的每张幻灯片上创建带有多个图表的PowerPoint - Creating a powerpoint with multiple charts on each slide from excel using vba 将图表从Excel复制到PowerPoint时更改幻灯片标题 - Change Slide Title while copying chart from excel to powerpoint 将图表从Excel复制到Powerpoint,以保持源格式并嵌入图表 - Copying charts from excel to powerpoint keeping source formatting and embedding the chart Excel / Powerpoint Office互操作-将图表从Excel工作表复制到Powerpoint幻灯片 - Excel/Powerpoint Office Interop - Copy chart from Excel Sheet to Powerpoint Slide 将选择的Excel图表复制到PowerPoint中的位置 - Copying select Excel charts to locations in PowerPoint 将所有表格和图表从所有Excel表格复制到PowerPoint - Copy all tables and charts from all sheets of Excel to PowerPoint VBA将同一工作表中的多个图表(每次4个)导出到一个powerpoint幻灯片中 - VBA export multiple charts (4 each time) from the same sheet into one powerpoint slide Excel 宏从 Excel 工作表复制表格并将其粘贴到 PowerPoint 幻灯片中,灵活地决定哪些列和行 - Excel Macro to copy a table from Excel Sheet and paste it in a PowerPoint Slide with flexibilty to decide which columns and rows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM