Apurv Pawar
Apurv Pawar

Reputation: 424

ppt paste from excel clipboard to slide

I have a chart range copied from excel. Now I want to paste it as picture in slide 5 of active presentation, but it is giving me below error.

"Shapes(unknown member):Invalid request.Clipboard is empty or contains data which may not be pasted here."

Please help, code below.

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

Upvotes: 0

Views: 1722

Answers (2)

Shai Rado
Shai Rado

Reputation: 33662

Try the code below (explanation inside the code comments):

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

Upvotes: 1

ksauter
ksauter

Reputation: 112

Try this:

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

Upvotes: 0

Related Questions