【问题标题】:ppt paste from excel clipboard to slideppt从excel剪贴板粘贴到幻灯片
【发布时间】:2017-11-06 23:00:01
【问题描述】:

我有一个从 Excel 复制的图表范围。现在我想将它作为图片粘贴到活动演示文稿的幻灯片 5 中,但它给了我以下错误。

“形状(未知成员):无效请求。剪贴板为空或包含可能无法粘贴到此处的数据。”

请帮忙,下面的代码。

Sub UpdateCharts()
Dim oPP As PowerPoint.Slide
Dim shp As PowerPoint.shape
ActivePresentation.Slides(5).Shapes.Paste
End Sub

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    试试下面的代码(代码cmets里面的解释):

    Option Explicit
    
    '=====================================================================
    ' This sub exports a range from Excel to PowerPoint,
    ' pastes it, and later on modifies it's position and size (if needed)
    ' The code works using Late-Binding, so there's no need
    ' to add References to the VB Project
    '=====================================================================
    
    Sub UpdateCharts()
    
    Dim ppApp                               As Object
    Dim ppPres                              As Object
    Dim ppSlide                             As Object
    Dim ppShape                             As Object
    
    ' check if PowerPoint application is Open
    On Error Resume Next
    Set ppApp = GetObject(, "PowerPoint.Application")
    On Error GoTo 0
    
    If ppApp Is Nothing Then
        MsgBox "PowerPoint Application is not open", vbCritical
        Exit Sub
    End If    
    
    ' set the Active Presentation
    Set ppPres = ppApp.ActivePresentation
    
    ' set the Slide
    Set ppSlide = ppPres.Slides(5)
    
    ' --- copy the Chart's Range (from Excel) ---
    ' <-- put your copy section here, right before the Paste
    'With Worksheets("toPPT")            
    '    .Range("F6:J7").Copy
    'End With
    
    ' --- Paste to PowerPoint and modify properties (if needed) ---
    Set ppShape = ppSlide.Shapes.PasteSpecial(3, msoFalse) ' 3 = ppPasteMetafilePicture
    ' modify properties of the pasted Chart (if needed)
    With ppShape
        .Left = 535
        .Top = 86
    End With
    Application.CutCopyMode = False
    
    ppPres.Save
    
    Set ppSlide = Nothing
    Set ppPres = Nothing
    Set ppApp = Nothing
    
    End Sub
    

    【讨论】:

      【解决方案2】:

      试试这个:

        mySlide.Shapes.PasteSpecial DataType:=2  '2 = ppPasteEnhancedMetafile
        Set myShape = mySlide.Shapes(mySlide.Shapes.(5))
      

      【讨论】:

        猜你喜欢
        • 2017-09-17
        • 2018-02-17
        • 2015-07-29
        • 1970-01-01
        • 2021-03-14
        • 1970-01-01
        • 2014-10-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多