?
Solved

How do i open up a new PP presentation from template file from Windows using VBA

Posted on 2012-03-18
3
Medium Priority
?
339 Views
Last Modified: 2012-03-25
Hi!

I have managed to open a PPT file using  the Shell and the run command.

" objShell = CreateObject("Wscript.Shell") "

But the problem is that it opens up the template itself, and it doesn't understand that it is supposed to generate a new document from the template when it opens up PowerPoint?
0
Comment
Question by:Musiqal
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 37736498
Try the following ... but modify the template string as appropriate.  I have shown two methods for adding a slide ... one direct and one to a variable ... the choice of which to use is yours.  The fist slide not surprisingly has to be '1' but after that change the first parameter to the add command to represent the slide to be added i.we. 1 adds as the first slide, 3 adds as the third slide BUT must never exceed the current number of slides by more than 1:

Sub presNew()
Dim pptApp As Object
Dim pres As Object
Dim strTemplate As String
Dim sld As Object
Const ppLayoutFourObjects As Integer = 24
Const ppLayoutTitle As Integer = 1

    strTemplate = "C:\Program Files\Microsoft Office\Templates\Presentation Designs\cliff.pot"
    Set pptApp = CreateObject("powerpoint.application")
    With pptApp.Presentations.Open(strTemplate, False, True, True)
                'Add slides as required ... i.e.
        .slides.Add 1, ppLayoutFourObjects
        Set sld = .slides.Add(1, ppLayoutTitle)
        sld.Shapes(1).TextFrame.textrange.Text = "I'm NEW!"
    End With

End Sub

Open in new window

0
 

Author Comment

by:Musiqal
ID: 37751403
This would have been great, but the problem is the slides need to be there from the beginning, any ideas?
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 37751771
If the slides exist in the template then they ought to be there ... the extra code supplied was to show how to add additional slides to the file derived from the template.

Chris
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

With the internet and the ease of information transference, many professional jobs can be done anywhere today.  Why should it make a difference whether an x-ray is read in India or the United States as long as the radiologist is qualified?   Outso…
When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
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…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

864 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