利用vba在excel中生成ppt!

本文详细介绍了如何使用Visual Basic for Applications (VBA) 编程语言,通过编写简单的代码来创建PowerPoint演示文稿,并在代码中实现新建演示文稿、添加新幻灯片、设置幻灯片布局、添加标题、插入图片和保存演示文稿等基本功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    'Declare variables
    Dim PP As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.slide
    Dim SlideTitle As String


    'Open PowerPoint and create new presentation
    Set PP = New PowerPoint.Application
    Set PPPres = PP.Presentations.Add
    PP.Visible = True
    
    'Add new slide as slide 1 and set focus to it
    Set PPSlide = PPPres.Slides.Add(1, ppLayoutChart)
    PPSlide.Select
    
    'Add the title to the slide
    SlideTitle = "My First PowerPoint Slide"
    PPSlide.Shapes.Title.TextFrame.TextRange.Text = SlideTitle

    ''Add the picture to the slide
    PPSlide.Shapes.AddPicture("C:\Users\GZQ\Desktop\IMG_3428.JPG", msoCTrue, msoFalse, 0, 0).Select

    'Save the slide
    PPPres.SaveAs "MyFirstPresentation.pptx"
    PP.Activate
    
    'Memory Cleanup
    Set PPSlide = Nothing
    Set PPPres = Nothing

 在编写之前一定要引用powerpoint的类库,在VBA界面,工具->引用,找到Microsoft powerpoint相关的类库。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值