[Last Call] Learn how to a build a cloud-first strategyRegister Now


Applying Slide Master using VB

Posted on 2006-06-06
Medium Priority
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
  • 3
  • 2
  • 2
LVL 22

Expert Comment

ID: 16844901
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

ID: 16849101
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

bruintje earned 2000 total points
ID: 16849202
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.


Author Comment

ID: 16849240
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

ID: 16849302
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

ID: 16849475
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

ID: 16851633
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.

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Quickbooks hosting can do wonders to your enterprise but considering the points elaborated in the article which will help you to better analyze the outcomes. So scan your business, its needs and then move to the new world of limitless benefits.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

825 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