简体   繁体   中英

Copy Excel Table Paste to Specific PPT Slide

Details: Mac Excel (2016) copying to Mac PPT (2016)

Eventually, I would like to loop through all tables and paste each table on its own individual slide in PPT.

But first I'm trying to simply copy one table from Excel and paste to a Specific PPT File (not a net new presentation).

Sub OpenPPTandCopySelectedTable()

Dim PPT As PowerPoint.Application   
Set PPT = New PowerPoint.Application
PPT.Visible = True

'Open the specific Template
PPT.Presentations.Open Filename:="/Users/MyNameHere/Downloads/FileName.pptx"

'Make Specific File the Active Presentation
Set PPPres = PPT.ActivePresentation

'Copy the Excel Table
Range("Table1[#All]").Copy

'Select PowerPoint Slide number 2
PPT.Slides(2).Select

'Paste Special 
Application.ActiveWindow.View.PasteSpecial DataType:=ppPastePNG

End Sub

What am I doing wrong? Any help would be appreciated.

Try the code below (without using Select and ActivePresentation , which slows down the run-time of your code).

Option Explicit

Sub OpenPPTandCopySelectedTable()

Dim PPT As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim myShape As Object

Set PPT = New PowerPoint.Application

' Open the specific Template and set it (in 1 line)
Set PPPres = PPT.Presentations.Open(Filename:="/Users/MyNameHere/Downloads/FileName.pptx", ReadOnly:=msoFalse)

'Copy the Excel Table
Range("Table1[#All]").Copy

' Paste to PowerPoint and set to MyShape
'Set myShape = PPPres.Slides(2).Shapes.PasteSpecial(ppPastePNG, msoFalse)
' if you want to edit the properties
'With myShape
    '.Left = 
    '.Top =    
'End With

' Option 2: 
PPPres.Slides(2).Shapes.PasteSpecial (ppPastePNG)

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM