简体   繁体   English

在VBA powerpoint中如何将新幻灯片添加到空的演示文稿中

[英]in VBA powerpoint How to add a new slide to an empty presentation

I want to add a new slide to an empty presentation. 我想在一个空的演示文稿中添加一张新幻灯片。 I am struggling with the layout. 我正在努力布局。 I am Using the following: 我使用以下内容:

Set pptLayout = ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1)
Set sld = ActivePresentation.Slides.AddSlide(1, pptLayout)
sld.Design = ActivePresentation.Designs(1)

This code works fine when i already have a slide in my presentation, but i don't! 当我的演示文稿中已有幻灯片时,此代码工作正常,但我没有!

So, my question is: how can i insert a slide if i don't have a preexisting slide to set the layout from it? 所以,我的问题是:如果我没有预先存在的幻灯片来设置它的布局,我怎么能插入幻灯片? I mean in the first line of the code i am defining a layout using slide 1 in order to use it in the .AddSlide 我的意思是在代码的第一行,我使用幻灯片1定义布局,以便在.AddSlide中使用它

You can simply use something like this : 你可以简单地使用这样的东西:

ActivePresentation.Slides.Add Index:=ActivePresentation.Slides.Count + 1, Layout:=ppLayoutCustom

With that you don't have to get the layout from elsewhere and you can change it, see some of the other possiblities that you have on screenshot : 有了这个, 你不必从其他地方获得布局 ,你可以改变它,看看你在屏幕截图上的其他一些可能性:

在此输入图像描述

A variation of the OP's code works for me OP代码的变体对我有用

Dim appPPT As PowerPoint.Application
dim ppObj As PowerPoint.Presentation
dim slideObj As PowerPoint.Slide
dim pptLayout As CustomLayout

Set appPPT = New PowerPoint.Application
Set ppObj = appPPT.Presentations.Add
Set pptLayout = ppObj.Designs(1).SlideMaster.CustomLayouts(7)
Set slideObj = ppObj.Slides.AddSlide(1, pptLayout)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM