1

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

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

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

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

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

4

2 回答 2

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 提示。

于 2013-04-02T14:30:26.710 回答
0

如果您想将 Excel 图表作为 Unliked 对象粘贴到 PowerPoint 中,但仍将其作为嵌入的 OLEObject 进行维护,我建议您将其粘贴为 OLEObject。粘贴看起来像这样:

'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 频道。

于 2018-12-14T18:38:28.930 回答