简体   繁体   English

如何将多个 Excel 图表粘贴到 PowerPoint 演示文稿中?

[英]How to paste multiple Excel charts into a PowerPoint presentation?

I'm trying to paste charts from Excel being into PowerPoint in specific locations.我正在尝试将 Excel 中的图表粘贴到特定位置的 PowerPoint 中。

I get an error when pasting a second slide粘贴第二张幻灯片时出现错误

Invalid request.无效请求。 To select a shape its view must be active要选择一个形状,它的视图必须处于活动状态

I have seen to use ActiveWindow.View.GotoSlide oSlide.SlideIndex and I know what I'm trying to do.我已经看到使用ActiveWindow.View.GotoSlide oSlide.SlideIndex并且我知道我想要做什么。 I just do not know how to implement this.我只是不知道如何实现这一点。

Sub ChartToPresentation()
    ' Uses Early Binding to the PowerPoint Object Model
    ' Set a VBE reference to Microsoft PowerPoint Object Library
    Dim PPApp  As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide
    Dim nPlcHolder As Long

    ' Reference existing instance of PowerPoint
    Set PPApp = GetObject(, "Powerpoint.Application")
    ' Reference active presentation
    Set PPPres = PPApp.ActivePresentation
    PPApp.ActiveWindow.ViewType = ppViewSlide

    'Copy "Chart 1" on "Sheet1" to Slide # 1
    ' Copy "Chart 1" on "Sheet1" as a picture and want to paste to placeholder 
    ActiveWorkbook.Sheets("Sheet1").ChartObjects("Chart 1").CopyPicture
    ' Paste chart  to Slide # 1
    With PPPres
        nPlcHolder = 2 '<~~ The place holder where you have to paste
        .Slides(1).Shapes.Placeholders(nPlcHolder).Select msoTrue
        .Windows(1).View.PasteSpecial (ppPasteMetafilePicture)
    End With

    'Copy "Chart 5" on "Sheet1" to Slide # 2
    ActiveWorkbook.Sheets("Sheet1").ChartObjects("Chart 5").CopyPicture
    ' Paste chart  to Slide # 2
    With PPPres
        nPlcHolder = 2 '<~~ The place holder where you have to paste
        .Slides(2).Shapes.Placeholders(nPlcHolder).Select msoTrue
        .Windows(1).View.PasteSpecial (ppPasteMetafilePicture)
    End With

End Sub

If you just select the slides it works:如果您只选择幻灯片,它会起作用:

With PPPres
     nPlcHolder = 2 '<~~ The place holder where you have to paste
    '.Slides(1).Shapes.Placeholders(nPlcHolder).Select msoTrue
    .Slides(1).Select
    .Windows(1).View.PasteSpecial (ppPasteMetafilePicture)
End With

[...]

With PPPres
     nPlcHolder = 2 '<~~ The place holder where you have to paste
    '.Slides(2).Shapes.Placeholders(nPlcHolder).Select msoTrue
    .Slides(2).Select
    .Windows(1).View.PasteSpecial (ppPasteMetafilePicture)
End With

After copying the charts to your PowerPoint slides you may want to move and zoom them by changing their picture properties.将图表复制到 PowerPoint 幻灯片后,您可能希望通过更改其图片属性来移动和缩放它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM