Log in

View Full Version : Solved: Apply a specific master to a new slide in PowerPoint



boy_plunder
08-24-2009, 03:18 AM
Hi all,

I have a presentation with 14 different masters. Each master is the same, but has a different colour, which is used to separate the presentations into sections.

I have written some code that inserts a new side, assigns a master and than adds a text slide that follows the design. The problem I am having is that I can't work out how the assign a specific master from the 14. All of the masters have unique names. Is there a way of applying a master to the slide by name?

John Wilson
08-24-2009, 04:11 AM
Good idea to state the version of ppt. Masters are very different in 2007.

Maybe something like this though.

Dim osld As Slide
Set osld = ActivePresentation.Slides.Add(1, ppLayoutTitle)
osld.Design = ActivePresentation.Designs("TheName")

boy_plunder
08-24-2009, 04:24 AM
Good idea to state the version of ppt. Masters are very different in 2007.

Very good point. This presentation is entirely for 2003.

boy_plunder
08-24-2009, 05:22 AM
Here is the code I am currently working with. I have tried to tie in the example you gave, but it errors on the 'Set osld =' line.


Sub InsertAviationslide()
Dim oView As View
Dim osld As Slide

With ActivePresentation.Slides
Set oView = ActiveWindow.View
oView.gotoslide .Add(oView.Slide.SlideIndex + 1, _
ppLayoutTitleOnly).SlideIndex
Set oView = Nothing
End With
Set osld = ActivePresentation.Slides.Add(oView.Slide.SlideIndex + 1, ppLayoutTitleOnly).SlideIndex
osld.Design = ActivePresentation.Designs("Aviation")

'Now add a new text slide for this divider
With ActivePresentation.Slides
Set oView = ActiveWindow.View
oView.gotoslide .Add(oView.Slide.SlideIndex + 1, _
ppLayoutTitleOnly).SlideIndex
Set oView = Nothing
End With

End Sub

The key points I'm trying to achieve are: Insert directly after the current slide, which will be in normal view, add the title slide and assign the correct master by name, and then add another slide that will be a standard text slide using the same master. [Which is a default action anyway.]

EDIT: I can see why! Will amend it.

John Wilson
08-24-2009, 06:49 AM
Does this work?
Sub InsertAviationslide2()
Dim lngInsert As Long
Dim osld As Slide

lngInsert = ActiveWindow.View.Slide.SlideIndex

Set osld = ActivePresentation.Slides.Add(lngInsert + 1, ppLayoutTitleOnly)
osld.Design = ActivePresentation.Designs("Aviation")
'Now add a new text slide for this divider
ActiveWindow.View.GotoSlide (osld.SlideIndex)
lngInsert = ActiveWindow.View.Slide.SlideIndex
Set osld = ActivePresentation.Slides.Add(lngInsert + 1, ppLayoutText)
osld.Design = ActivePresentation.Designs("Aviation")
Set osld = Nothing
End Sub
I can't get your code to work but one reason is you set oView to nothing and then tried to use it

I think in vba adding a new slide doesn't use the last master as it does in manual adding.

boy_plunder
08-24-2009, 07:17 AM
John Wilson, you're worth your weight in gold.

The first Set osld line needed to end ppLayoutTitle, not ppLayoutTitleOnly, then it works perfectly.

Like this:

Sub InsertAviationslide2()
Dim lngInsert As Long
Dim osld As Slide

lngInsert = ActiveWindow.View.Slide.SlideIndex

Set osld = ActivePresentation.Slides.Add(lngInsert + 1, ppLayoutTitle)
osld.Design = ActivePresentation.Designs("Aviation")
'Now add a new text slide for this divider
ActiveWindow.View.gotoslide (lngInsert + 1)
lngInsert = ActiveWindow.View.Slide.SlideIndex
Set osld = ActivePresentation.Slides.Add(lngInsert + 1, ppLayoutText)
osld.Design = ActivePresentation.Designs("Aviation")
Set osld = Nothing
End Sub

Your help is very much appreciated.

John Wilson
08-24-2009, 07:49 AM
"John Wilson, you're worth your weight in gold."

If only - I'd be a millionaire at least!