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

被折叠的 条评论
为什么被折叠?



