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

时间:2022-07-24 13:00:23

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中使用它

2 个解决方案

#1


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 :

有了这个,你不必从其他地方获得布局,你可以改变它,看看你在屏幕截图上的其他一些可能性:

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

#2


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)

#1


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 :

有了这个,你不必从其他地方获得布局,你可以改变它,看看你在屏幕截图上的其他一些可能性:

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

#2


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)