How do I use my powerpoint template through VBA in order to build my desired slides?

Viewed 201

I cant figure out how to incorporate my template into my actual code in VBA so that my sheets will build in the desired template and slides.

I have built the slides in a new blank powerpoint slides but cant figure out how to do it with template yet.

Sub LCTAKT_Macro()
    'Declare variables
    Dim PP As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide1 As PowerPoint.Slide
    Dim PPSlide2 As PowerPoint.Slide
    Dim PPSlide3 As PowerPoint.Slide
    Dim PPSlide4 As PowerPoint.Slide
    Dim PPSlide5 As PowerPoint.Slide
    Dim PPSlide6 As PowerPoint.Slide
    Dim PPSlide7 As PowerPoint.Slide
    Dim SlideTitle As String
    Dim objPPT As Object

    'Open PowerPoint and create new presentation
    Set objPPT = CreateObject("PowerPoint.Application")
    objPPT.Visible = True

    Set PP = New PowerPoint.Application
    Set PPPres = PP.Presentations.Add
    PP.Visible = True

    objPPT.Presentations.Open ""

    '-------------------------------------------------Station 42---------        ------------------------------------------------
    'Add new slide as slide 2 and set focus to it
    Set PPSlide1 = PPPres.Slides.Add(1, ppLayoutTitleOnly)
    PPSlide1.Select

    'Copy the range as a picture
    Sheets("").Range("A1:W59").CopyPicture _
    Appearance:=xlScreen, Format:=xlPicture

    'Paste the picture and adjust its position
    PPSlide1.Shapes.Paste.Select
    PP.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
    PP.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

    'Add the title to the slide
    SlideTitle = ""
    PPSlide1.Shapes.Title.TextFrame.TextRange.Text = SlideTitle

    'Position pasted chart
    PP.ActiveWindow.Selection.ShapeRange.Left = 200
    PP.ActiveWindow.Selection.ShapeRange.Top = 130
    PP.ActiveWindow.Selection.ShapeRange.Height = 523
    PP.ActiveWindow.Selection.ShapeRange.Width = 554

I expect the template to be incorporated in the slides while still building the necessary data snippets to it.

1 Answers

Assuming Office 2013 or better, try this:

TemplateName$ = "C:\Users\YourActualUserName\Documents\Custom Office Templates\YourActualTemplateName.potx"
Set PPPres = PP.Presentations.Open(TemplateName$, False, True, True)
Related