简体   繁体   English

复制 Excel 表格粘贴到特定的 PPT 幻灯片

[英]Copy Excel Table Paste to Specific PPT Slide

Details: Mac Excel (2016) copying to Mac PPT (2016)详情:Mac Excel (2016) 复制到 Mac PPT (2016)

Eventually, I would like to loop through all tables and paste each table on its own individual slide in PPT.最后,我想遍历所有表格并将每个表格粘贴到 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).但首先我试图简单地从 Excel 复制一个表格并粘贴到一个特定的 PPT 文件(不是一个全新的演示文稿)。

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).试试下面的代码(不使用SelectActivePresentation ,这会减慢代码的运行时间)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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