【问题标题】:Chart sheet copy and pasted to power point图表表复制并粘贴到电源点
【发布时间】: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


【解决方案1】:

我最近完成了将图表从图表表复制并粘贴到 Word 文档中的过程。我最终不得不绕道而行,但我发现从图表表中复制/粘贴图表的唯一方法就是这样做......

Charts("Name Of Chart Sheet").Select
Selection.Copy

然后,您可以继续将其粘贴到您要查找的任何位置。否则,当我复制它时,它会创建一个带有新图表表的新工作簿。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 1970-01-01
    • 2020-12-21
    • 2015-02-06
    相关资源
    最近更新 更多