Consulting

Results 1 to 7 of 7

Thread: Solved: Apply a specific master to a new slide in PowerPoint

  1. #1

    Solved: Apply a specific master to a new slide in PowerPoint

    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?

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Good idea to state the version of ppt. Masters are very different in 2007.

    Maybe something like this though.

    [VBA]Dim osld As Slide
    Set osld = ActivePresentation.Slides.Add(1, ppLayoutTitle)
    osld.Design = ActivePresentation.Designs("TheName")[/VBA]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Good idea to state the version of ppt. Masters are very different in 2007.
    Very good point. This presentation is entirely for 2003.

  4. #4
    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.
    Last edited by boy_plunder; 08-24-2009 at 06:45 AM.

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Does this work?
    [vba]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[/vba]
    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.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    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.

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    "John Wilson, you're worth your weight in gold."

    If only - I'd be a millionaire at least!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •