In Powerpoint VBA How to Add New Slide to Blank Presentation
I want to add a new slide to a blank presentation. I am struggling with 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 great 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 an existing slide in order to set the layout from it? I mean in the first line of code I define the layout using slide 1 in order to use it in .AddSlide
+3
source to share
2 answers
You can simply use something like this:
ActivePresentation.Slides.Add Index:=ActivePresentation.Slides.Count + 1, Layout:=ppLayoutCustom
With this, you don't need to get the layout from elsewhere and you can change it, see some of the other possibilities you have in the screenshot:
+2
source to share
OP's code option 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)
0
source to share