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

时间:2015-10-12 15:13:22

标签: excel vba excel-vba powerpoint powerpoint-vba

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

有人可以告诉我怎么做吗?

add_action( 'woocommerce_product_query', 'hs_product_query' );
function hs_product_query( $q ){

    $product_type = array(
      'taxonomy' => 'product_type',
      'field' => 'slug',
      'terms' => 'grouped'
    );
    $q->set('tax_query', array($product_type) );

    $q->set( 'post_parent', 0 );
}

1 个答案:

答案 0 :(得分:1)

小心:如果收藏品为空,则无法粘贴幻灯片的形状

即。 :您需要一张至少包含标题或形状(正方形,三角形......)的幻灯片,以便将您复制的内容粘贴到剪贴板中。

以下是基础知识,您应该更正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