2017-04-21 136 views
1

详情: Mac的Excel文件(2016)复制到Mac地产(2016)复制Excel表格粘贴到具体的PPT幻灯片

最后,我想通过所有的表环和粘贴在它自己单独的幻灯片每个表PPT。

但首先我试图从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 

我在做什么错?任何帮助,将不胜感激。

+2

首先,请将OPTION EXPLICIT添加到代码模块的第一行。让它成为一种习惯,你会在生活中变得更加幸福。其次,您的PasteSpecial行使用“应用程序”,这将是Excel,但我认为您希望它是PowerPoint应用程序。使用PPT.ActiveWindow.View.PasteSpecial ... –

+2

^^此外,我不经常使用Powerpoint VBA(即从不),但应该'PPT.Slides(2).Select'为'PPPres.Slides(2)。 Select'?我希望“幻灯片”可以是演示文稿的属性,而不是Powerpoint应用程序的属性。 – YowE3K

回答

1

请尝试下面的代码(不使用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 
+0

收到编译错误:未找到方法或数据成员。它突出显示了“Set myShape = PPPres.Slides(2).Shapes.PasteSpecial(ppPastePNG,msoFalse)”代码行中的“.PasteSpecial”。 –

+0

@BenSimmons你什么时候更新它的MAC?我无法在MAC上测试它,因为我正在使用PC。我已经添加了第二个选项,看它可能适用于你 –

+0

我在原来的描述中使用了它。这看起来是问题。 'PasteSpecial(ppPastePNG)'似乎是问题所在。不知道如何完成是MAC PPT。接收与以前相同的错误。 –