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 @   GYT_Robot  阅读(204)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
点击右上角即可分享
微信分享提示