当前位置: 首页 > 知识库问答 >
问题:

将Excel图表作为图片导出到PowerPoint

杨飞语
2023-03-14

我有一个excel工作簿,每张工作表有一个图表和多个工作表,我试图将所有图表作为图片导出到PowerPoints中。问题是我的当前代码无法工作。我的代码出现错误:

>

  • 简报按预期打开

    将复制我在运行前选择的活动工作表的图表

    复制的图表粘贴在PowerPoint中

    PowerPoint创建下一张幻灯片

    现在问题再次复制同一工作表中的同一图表!我希望代码移动到下一张工作表,选择上面的图表,并在下一张幻灯片中复制过去!

    SubTEST_ExportChartsToPowerPoint_SingleWorkbook()'Declare PowerPoint Object Variables Dim pptApp AsPowerPoint.ApplicationDim pptPres AsPowerPoint.PresentationDim pptSlide AsPowerPoint.SlideDim SldIndex As intger'Declare Excel Object Variables Dim Chr t As ChartObject'Dim Chr t As ChartArea Dim WrkSht As Worktable

     '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
    

    端接头

  • 共有1个答案

    黄跃
    2023-03-14

    问题在于如何参考图表。看看你的循环:

    '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
    

    即使您循环遍历所有工作表,您也只能引用ActiveChart。您需要在循环中引用工作表上的图表。默认情况下,ActiveChart引用活动工作表上的图表。这就是为什么为每张幻灯片复制相同的图表,因为引用永远不会更改。所以您需要更改对循环中当前工作表的引用。

    更改以下行

    ActiveChart.ChartArea.Select
    ActiveChart.ChartArea.Copy
    

    WrkSht.ChartObjects(1).Chart.ChartArea.Copy
    

    此代码正确地引用了图表。还请注意,您不需要使用<code>。选择图表区的方法。

     类似资料:
    • 我编写了以下简单的C#控制台应用程序,用于从Excel工作簿导出所有图表。它工作正常,除非打开文档后图表没有滚动到,在这种情况下会生成一个空的图像文件。 我尝试了几次滚动到该对象的失败尝试;程序底部注释掉的行(

    • 问题内容: 我一直试图将Excel中的图表导出为Python中的图像文件(JPG或ING)。我正在看WIn32com。这是我到目前为止所拥有的。 这就是我被困住的地方。我现在需要将所选范围复制到文件中。对文档的任何帮助或指导都可以对我有很大帮助。 我已经基于以下VBA脚本对以上代码进行了建模: 来自以下代码段:http://vbadud.blogspot.com/2010/06/how-to-sa

    • 用html方式table导出excel,多张图片放在td里怎么自动排列,现在导出只会重叠在一起,样式怎么写

    • 我想将股票图表ohlc导出到Excel 我正在使用EPPlus,现在我知道EPPlus不支持绘制股票图表,因此我正在寻找另一个第三方dll,我找到了aspose,但它是一种付费功能。 有人能推荐其他方法导出股票图表用C#代码在Excel中创建股票图表吗? 或者它是可能的创建股票图表ohlc在Excel由C#由EPPlus? 当使用aspal时,我需要在bw代码中使用它,在我保存aspal工作簿的时

    • 我正试图将数据从Excel导入到SQL Server表中,但遇到了这个错误。你能建议如何避免这些吗?

    • 我正在使用以下代码将带有图像的数据导出到Excel。 密码 Excel正在正常下载。但问题是当我过滤中的数据时。中的图像位于属性调整大小。如何使图像与属性,?