Vba 打开PowerPoint并从Excel复制到特定幻灯片

Vba 打开PowerPoint并从Excel复制到特定幻灯片,vba,excel,powerpoint,Vba,Excel,Powerpoint,我想打开现有的PowerPoint模板并选择幻灯片3,然后将表格从电子表格复制到PowerPoint幻灯片 有人能告诉我怎么做吗 Sub Open_PowerPoint_Presentation() 'Opens a PowerPoint Document from Excel Dim objPPT As Object Dim PPSlide As Object Set objPPT = CreateObject("PowerPoint.Application")

我想打开现有的PowerPoint模板并选择幻灯片3,然后将表格从电子表格复制到PowerPoint幻灯片

有人能告诉我怎么做吗

Sub Open_PowerPoint_Presentation()
'Opens a PowerPoint Document from Excel

    Dim objPPT As Object
    Dim PPSlide As Object

    Set objPPT = CreateObject("PowerPoint.Application")
    Set PPSlide = objPPT.Slides(5)

    objPPT.Visible = True

    'Change the directory path and file name to the location
     'of your document

    objPPT.Presentations.Open "\\MI-FILESERVE1\Shared Folders\Shared_Business_Dev\assets\Tender Time Allocation Deck.pptx"

    PPSlide.Select




     End Sub

小心:如果集合为空,则无法粘贴幻灯片的形状。

例如:你需要一张至少有标题或形状(正方形、三角形等)的幻灯片才能粘贴你在剪贴板上复制的内容

以下是基础知识,您应该更正excel行以复制所需内容:

Sub Open_PowerPoint_Presentation()

Dim objPPT As Object, _
    PPTPrez As PowerPoint.Presentation, _
    pSlide As PowerPoint.Slide

Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True

Set PPTPrez = objPPT.Presentations.Open("\\MI-FILESERVE1\Shared Folders\Shared_Business_Dev\assets\Tender Time Allocation Deck.pptx")
Set pSlide = PPTPrez.Slides(5)

If pSlide.Shapes.Count <> 0 Then
    'Table
    ActiveWorkbook.Sheets("Sheet1").Range("Named Range").Copy
    pSlide.Shapes.PasteSpecial DataType:=ppPasteEnhancedMetafile
    'OR
    ActiveWorkbook.Sheets("Sheet1").Range("Named Range").CopyPicture
    pSlide.Shapes.Paste

    'Charts
    ActiveWorkbook.Sheets("Graph1").ActiveChart.ChartArea.Copy
    pSlide.Shapes.PasteSpecial DataType:=ppPasteEnhancedMetafile
    'OR
    ActiveWorkbook.Sheets("Graph1").ActiveChart.ChartArea.CopyPicture
    pSlide.Shapes.Paste
Else
    MsgBox "There is no shape in this Slide (" & pSlide.SlideIndex & ")." & vbCrLf & "Please use a slide with at least one shape, not a blank slide", vbCritical + vbOKOnly
End If

End Sub
子打开\u PowerPoint\u演示文稿()
作为对象的Dim objPPT_
PPTPrez作为PowerPoint.Presentation_
pSlide作为PowerPoint.Slide
设置objPPT=CreateObject(“PowerPoint.Application”)
objPPT.Visible=True
设置PPTPrez=objPPT.Presentations.Open(\\MI-FILESERVE1\Shared Folders\Shared\u Business\u Dev\assets\Tender Time Allocation Deck.pptx)
设置pSlide=PPTPrez.幻灯片(5)
如果pSlide.Shapes.Count为0,则
“桌子
ActiveWorkbook.Sheets(“Sheet1”).Range(“命名范围”).Copy
pSlide.Shapes.PasteSpecial数据类型:=ppPasteEnhancedMetafile
”“或者
ActiveWorkbook.Sheets(“Sheet1”).Range(“命名范围”).CopyPicture
pSlide.Shapes.Paste
“图表
ActiveWorkbook.Sheets(“Graph1”).ActiveChart.ChartArea.Copy
pSlide.Shapes.PasteSpecial数据类型:=ppPasteEnhancedMetafile
”“或者
ActiveWorkbook.Sheets(“Graph1”).ActiveChart.ChartArea.CopyPicture
pSlide.Shapes.Paste
其他的
MsgBox“此幻灯片中没有形状(“&pSlide.SlideIndex&”)。&vbCrLf&“请使用至少有一个形状的幻灯片,而不是空白幻灯片”,vbCritical+vbOKOnly
如果结束
端接头

谢谢,我尝试了你的代码,但是我得到了以下错误:形状(未知成员)无效请求。剪贴板是空的或包含可能无法粘贴到此处的数据非常感谢,这似乎可以解决问题。我非常感谢你的帮助,并对任何误解表示歉意。别担心,每个人都会有开始的时候。我将在副本中解释误解,以澄清问题。不管怎样,我很高兴能帮上忙。享受吧;)