I have the following VBA code to create a new PowerPoint slide:
longSlideCount = ActivePresentation.Slides.Count
With ActivePresentation.Slides
Set slideObject = .Add(longSlideCount + 1, ppLayoutTitle)
End With
...which inserts a new slide of type 'ppLayoutTitle', but I am wondering if it is possible to create a custom layout in the 'Slide Master View' and then insert that particular slide template into the presentation?
Thanks in advance!!!
All your custom layouts can be accessed via VBA through the
CustomLayouts
collection of theSlideMaster
property of aPresentation
object. When you create a custom layout, give it a meaningful name. Then you can fetch it from theCustomLayouts
collection. It appears that Microsoft didn't implement lookup by name, so you will have to iterate through the collection to find theCustomLayout
object with the right name.Once you have a reference to the desired
CustomLayout
object, you use theAddSlide
method of theSlides
collection, which takes aCustomLayout
object as the second arguments (as opposed toSlides.Add
, which you used in your question, and which takes aPpSlideLayout
enumeration value).Below is a helper method for fetching a custom layout by name, and example of using it as you wanted: