Applying Slide Master using VB

Posted on 2006-06-06
Last Modified: 2012-06-21
I have a PowerPoint template that has several slide masters.

Is there a way to apply a slide master (by name) to a the current slide using VB?

Question by:lp3535
    LVL 22

    Expert Comment

    I can't find a reference to controlling PowerPoint via script ... BUT ...
    You might be able to get the reference you need by recording a macro while doing this.
    If you start the recording of a macro, go through the steps of changing the reference to the Master and then save the macro, you should be able to go back and look at the code for the macro you just recorded and see what its doing "behind the scenes" to change what mater is applied to the template ... this should give you the code you need.

    Author Comment

    Hi cj_1969

    I have tried that already, but it only comes up with the following:

    ActivePresentation.ApplyTemplate filename:=""

    If I put an actual filename in, it applies the changes to the whole presentation, not just the current slide.

    PowerPoint is driving me nuts!
    LVL 44

    Accepted Solution

    in relation to your other question for the insert new slide after last slide you see the only way to apply a master for a slide is calling applytemplate

    i would create x presentations all having one slide with one master applied
    and in your code doing a case select statement to choose the appropriate srcFile template to use for the slide

    Author Comment

    Thanks bruintje !  You're an absolute legend!

    I realised that your answer to my last question solved a lot of my other questions.

    Sub InsertSlide()
    Dim trgPrez As Presentation
    Dim srcPrez As Presentation
    Dim newSlide As Slide
    Dim srcFile As String
        srcFile = "C:\test.ppt"
        Set trgPrez = ActivePresentation
        Set srcPrez = Application.Presentations.Open(filename:=srcFile, WithWindow:=msoFalse)
        trgPrez.Slides.InsertFromFile filename:=srcFile, _
          Index:=ActivePresentation.Slides.Count, SlideStart:=1, SlideEnd:=1
        Set newSlide = trgPrez.Slides(trgPrez.Slides.Count)
        newSlide.ApplyTemplate srcFile
        Set newSlide = Nothing
        Set srcPrez = Nothing
        Set trgPrez = Nothing
    End Sub

    Thanks again.

    Author Comment

    Hi bruintje,

    I think I might have been a bit hasty there.  How do I get this to just apply the template to the current slide, without inserting a new slide?
    LVL 44

    Expert Comment

    you can use this

    Sub ApplyTemplateToSlide()
    Dim trgSlide As Slide
    Dim srcFile As String
        srcFile = "c:\test.ppt"
        Set trgSlide = ActiveWindow.View.Slide
        trgSlide.ApplyTemplate srcFile
        Set trgSlide = Nothing

    End Sub

    but this only works in powerpoint 2003, can't test for XP but 2000 applied the template to the whole presentation
    if you need to code for powerpoint 2000 then its more complex and i don't think feaseable only from powerpoint XP you had the option of multiple masters per presentation which could be a drawback
    LVL 22

    Expert Comment

    The multiple master is only available in the 2002(XP)/2003 versions so you can't do what you want if you are running a 2000 or older version of PPT.
    You have to have the alternate master in the presentation, as long as you do you should be able to apply the master based on the name of it.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction It seems that at least a couple of times per month, I answer a question that requires automating Outlook from another Microsoft Office application, usually (although not always) to send one or more email messages.  For example: …
    Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
    This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
    The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now