Hello,

I am trying to copy a selected range from excel and paste it to the position where the selected placeholder is in powerpoint. I wrote the below code, but somehow it doesn't work. Could anyone please look at it and provide your potential solutions? Thank you very much.

ub CopyRange()


Dim PPApp As Object
Dim PPPres As Object
Dim PPSlide As Object
Dim PPShape As Object
Dim ActiveShape As Shape
Dim Shp As Shape
Dim w As Long, t As Long, l As Long


' Make sure a range is selected
If Not TypeName(Selection) = "Range" Then
MsgBox "Please select a worksheet range and try again.", vbExclamation, _
"No Range Selected"
Else
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
' Reference active slide
Set PPSlide = PPPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
' Reference active placeholder
If PPApp.ActiveWindow.Selection.Type = ppSelectionShapes Then
' Loop in case multiple shapes selected
For Each Shp In PPApp.ActiveWindow.Selection.ShapeRange
' Activeshape is the first shape selected
ActiveShape = Shp
Exit For
Next Shp

w = ActiveShape.Width
t = ActiveShape.Top
l = ActiveShape.Left
' Copy the range & paste the link
Selection.Copy
PPSlide.Shapes.PasteSpecial(Link:=True).Select



' Align the pasted range
With PPApp.ActiveWindow.Selection.ShapeRange
.Width = w
.Top = t
.Left = l
End With

' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
ActiveShape.Delete

Else
MsgBox "There is no shape currently selected!", vbExclamation, "No Shape Found"
End If

End If


Application.CutCopyMode = False



End Sub