VBA-custom layouts

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
 
M

Michael Koerner

I don't know anything about VBA. but, if I were doing something like this, I would initially create a blank slide with my picture box, and caption box all set up, then duplicate that slide every time I wanted to create a new one, insert my picture, and insert my text.

--
Michael Koerner
MS MVP - PowerPoint


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
 
S

Shyam Pillai

Use, the new AddSlide method available in PPT 2007

Set Sld = Pre.Slides.AddSlide(Pre.Slides.Count + 1,
ActivePresentation.SlideMaster.CustomLayouts(1))


Regards,
Shyam Pillai

Handout Wizard: http://skp.mvps.org/how
 
M

MM

Thankyou's to Michael Koerner and Shyam Pillai for their helpful responses
to my question re VBA-custom layouts. I found the AddSlide method a great
way to go for this!

Here's a follow-up question: How do I specify layouts by name or by number
(rather than by example) if using the AddSlide method?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top