VBA(一)操作PPT中的图片和表格

向PPT粘贴图片和表格数据

Sub CopyPictureToPPT()
    Set ppt = New PowerPoint.Application
    ppt.Presentations.Open "C:\Users\Administrator\Desktop\testforAutopadding\testForPicture.pptx", WithWindow:=msoFalse
    '插入图片'
    ppt.Presentations(1).Slides(1).Shapes(1).Fill.UserPicture ("C:\Users\Administrator\Desktop\testforAutopadding\" & "red.jpg")''
    ppt.Presentations(1).Slides(1).Shapes(2).Fill.UserPicture ("C:\Users\Administrator\Desktop\testforAutopadding\" & "blue.jpg")
    '插入表格数据'
    Dim oWs As Worksheet'新建工作表'
    Set oWs = ActiveWorkbook.Worksheets(1)'将当前活动工作簿的工作表1赋给oWs变量'
    '将当前打开的Excel中的表格数据粘贴给PPT中的表格'
    With ppt.Presentations(1).Slides(2).Shapes(2).Table
    .Cell(1, 1).Shape.TextFrame.TextRange.Text = oWs.Cells(1, 1)
    End With
    '保存PPT并关闭'
    With ppt.Presentations(1)
        .Save
    End With
    Set oWs = nothing
    ppt.Quit
    Set ppt = nothing
End Sub
posted @ 2022-09-18 15:18  GYT_Robot  阅读(291)  评论(0)    收藏  举报  来源