PDA

View Full Version : [SOLVED:] Paste selection to CURRENT PPT Slide



cwojtak
07-22-2019, 01:18 PM
This code pastes my current selection from Excel into a new slide on the current PPT presentation I have open. I need it to paste to the current slide I am on rather than a new slide.

Any advice is greatly appreciated.


Sub ExcelRangeToPowerPoint()

Dim rng As Range
Dim PowerPointApp As Object
Dim myPresentation As Object
Dim mySlide As Object
Dim myShape As Object


Set rng = Selection
rng.Copy


On Error Resume Next

Set PowerPointApp = GetObject(class:="PowerPoint.Application")

Err.Clear


If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")

If Err.Number = 429 Then
MsgBox "PowerPoint could not be found, aborting."
Exit Sub
End If


On Error GoTo 0



Set myPresentation = PowerPointApp.ActivePresentation

Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly 'THIS IS WHAT I NEED HELP WITH




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


myShape.Left = 66
myShape.Top = 152




PowerPointApp.Visible = True
PowerPointApp.Activate


Application.CutCopyMode = False

End Sub







Code listed was modified from -

https://www.thespreadsheetguru.com/blog/2014/3/17/copy-paste-an-excel-range-into-powerpoint-with-vba

Artik
07-22-2019, 02:10 PM
Try
Set mySlide = PowerPointApp.ActiveWindow.View.Slide

Artik

cwojtak
07-23-2019, 06:35 AM
Worked perfectly Artik. I was trying that with an s at the end of view for some reason. Regardless thank you for the help!!