4
votes

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

2
The code works fine for me. I created a new powerpoint. Deleted the starting slide and then ran the code. It added a new slide.Sam
So strange, that it works with you! I am not a VBA expert to tell why..Mohammed Hashim

2 Answers

1
votes

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 :

enter image description here

0
votes

A variation of the OP's code works for me

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)