将未链接的Excel图表粘贴到Powerpoint

时间:2013-04-01 02:50:01

标签: excel vba powerpoint paste

我目前正在开展一个项目,将50多组Excel图表传输到powerpoint演示文稿。我有50多个项目,我正在比较并制作50多个相同的图表。我在excel工作簿中设置它的方式是图表始终是相同的图表(即图表2),但通过更改唯一的ID号,我的图表将从工作表的不同区域获取。

在通常的情况下,我只是将图表复制并粘贴为图片。

但是,在我的情况下,我还需要删除所有数据标签<10%。我找到了一个代码来删除&lt; 10%数据标签在Powerpoint中,但不是excel。为了执行此代码,我必须将对象保持为“图表”格式。不幸的是,由于我将图表设置为可以提供不同数据的相同图表,每当我更改一个唯一的ID号以复制新图表时,我之前的图表已经被复制到Powerpoint“更新”中,看起来像信息来自最新项目。

我现在的选择是 1)一次复制和粘贴每个项目,在Powerpoint上运行我的数据标签代码,然后将该幻灯片中的所有内容转换为图片。这很乏味。 2)弄清楚如何在Excel中编辑数据标签,然后复制和粘贴为图像 3)最理想:将未链接的图表从Excel复制并粘贴到PPT。这允许我运行我的Powerpoint&lt; 10%格式化代码,但是取消链接还允许我更改我的Excel工作表而不会弄乱我当前的图表。

有没有人知道如何将未链接的图表从Excel复制并粘贴到不是图片的PPT?

2 个答案:

答案 0 :(得分:2)

以下是您的可能解决方案:

Sub Breaking_links()

Dim CHR As Shape

Set CHR = ActivePresentation.Slides(1).Shapes(3) 'for 3rd chart shape on 1st slide

CHR.Chart.ChartData.BreakLink

End Sub

简短说明 - 将图表复制到PP后,您需要断开上面示例的数据源链接。

此外,我认为您可以像在PP中一样简单地修改Excel中的轴。如果您发现该选项更好,请向我们展示您的PP代码,这将为您提供Excel的一些提示。

答案 1 :(得分:0)

如果要将Excel图表作为“不大对象”粘贴到PowerPoint中,但仍将其保留为嵌入式OLEObject,则我建议您将其作为OLEObject粘贴。粘贴应如下所示:< / p>

'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:=ppPasteOLEObject, Link:=msoFalse

这里有一些简单的代码,您可以将多个图表作为不带链接的OLEObject跨工作簿粘贴到PowerPoint演示文稿中。

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 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

    'Loop throught all the Worksheets in the Worksheets Collection.
    For Each WrkSht In Worksheets

        'Loop through all the CHARTOBJECTS in the ACTIVESHEET.
        For Each Chrt In WrkSht.ChartObjects

            'Copy the Chart
            Chrt.Chart.ChartArea.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:=ppPasteOLEObject, Link:=msoFalse

            '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

现在,这实际上是一些我在我的YouTube视频中浏览过的代码,因此,如果您想遍历整个代码,建议您访问下面的链接。

https://youtu.be/DOaBtYMCCEM

完全公开这是我的个人YouTube频道。