M
MM
I'm trying to automate the creation of some slides using VBA. I want to use
custom layouts and (for example) want to put the image filename in a caption
box under a picture box. Right now I'm stuck on the creation of slides with
a custom layout. Here's a snippet of VBA code:
Sub AddSlides_Custom()
Dim Pre As Presentation
Dim Sld As Slide
With ActivePresentation.SlideMaster
.CustomLayouts.Add (1)
.CustomLayouts(1).Name = "MyLayout"
End With
Set Pre = ActivePresentation
Set Sld = Pre.Slides.Add(Index:=Pre.Slides.Count + 1,
Layout:=ppLayoutMyLayout)
Sld.Shapes(1).TextFrame.TextRange = "My Title"
End Sub
The code successfully adds the layout "MyLayout." But it fails to create a
new slide with layout "MyLayout" and reports "Variable Not Defined." Note
that the code works fine if the line beginning "Set Sld = ..." specifies a
standard layout such as "object" or "twocolumntext" instead of "mylayout."
I'm pretty new at all this and am sure I'm making some elementary mistake,
but it has me confounded. Any help would be much appreciated.
I'd be most grateful if someone could advise me on this VBA question. I'm
custom layouts and (for example) want to put the image filename in a caption
box under a picture box. Right now I'm stuck on the creation of slides with
a custom layout. Here's a snippet of VBA code:
Sub AddSlides_Custom()
Dim Pre As Presentation
Dim Sld As Slide
With ActivePresentation.SlideMaster
.CustomLayouts.Add (1)
.CustomLayouts(1).Name = "MyLayout"
End With
Set Pre = ActivePresentation
Set Sld = Pre.Slides.Add(Index:=Pre.Slides.Count + 1,
Layout:=ppLayoutMyLayout)
Sld.Shapes(1).TextFrame.TextRange = "My Title"
End Sub
The code successfully adds the layout "MyLayout." But it fails to create a
new slide with layout "MyLayout" and reports "Variable Not Defined." Note
that the code works fine if the line beginning "Set Sld = ..." specifies a
standard layout such as "object" or "twocolumntext" instead of "mylayout."
I'm pretty new at all this and am sure I'm making some elementary mistake,
but it has me confounded. Any help would be much appreciated.
I'd be most grateful if someone could advise me on this VBA question. I'm