ppt从excel剪贴板粘贴到幻灯片

时间:2017-06-06 04:17:04

标签: excel vba

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

"形状(未知成员):无效的request.Clipboard为空或包含可能未在此处粘贴的数据。"

请帮忙,下面的代码。

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

2 个答案:

答案 0 :(得分:1)

尝试下面的代码(代码注释中的解释):

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

答案 1 :(得分:0)

试试这个:

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