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
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
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.