Consulting

Results 1 to 3 of 3

Thread: Add textboxes to slides after Inputfromfile

  1. #1
    VBAX Newbie
    Joined
    Dec 2016
    Posts
    2
    Location

    Add textboxes to slides after Inputfromfile

    Hello!

    I'm new to using the powerpoint library of VBA and I'm struggling with a project so if anyone has any advice or code samples I'd really appreciate it. I'm looking to take slides from an existing powerpoint, create a new powerpoint presentation with those slides, and then add textboxes and text to those slides. As an added complication, I need to take data from the excel sheet and create text on the created slides based on what that data says. Here is what I have so far. My question is how do I create textboxes and add text to the slides that I bring in using the insertfromfile method? I haven't assigned those slides as an object so the normal way of creating shapes doesn't make sense to me. I'm sure there's a way to do it but I'm not finding it... Would really love some help on this! Thanks!

    Sub create_template()
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''
    'Dimension variable and objects
    Dim ppapp As PowerPoint.Application
    Dim pppres As PowerPoint.Presentation
    Dim ppslide As PowerPoint.Slide
    Dim ppshape As Shape
    Dim Var_x As String
    Dim i As Integer

    'Open Powerpoint
    Set ppapp = CreateObject("Powerpoint.Application")
    ppapp.Visible = True
    Set pppres = ppapp.Presentations.Add
    ppapp.ActiveWindow.ViewType = ppViewSlide

    filepath = "C:\Users\jake"


    'Create Card Deck
    i = 1
    j = 1
    Do Until Sheet1.Cells(i + 1, 1).Value = "End"

    Var_x = Sheet1.Cells(i + 1, 1).Value

    If Var_x = "Option 1'" Then
    pppres.Slides.InsertFromFile filepath & "ARC_doc", 0, 2, 2
    ElseIf Var_x = "Option 2'" Then
    pppres.Slides.InsertFromFile filepath & "ARC_doc", 0, 3, 3
    ElseIf Var_x = "Option 3" Then
    pppres.Slides.InsertFromFile filepath & "ARC_doc", 0, 4, 4
    End If

    i = i + 1

    Loop


    'Save Output File
    With pppres
    .SaveAs "C:\Users\jake\outputdoc.pptx"
    .Close
    End With


    'Clean Up
    ppapp.Quit

    Set ppslide = Nothing
    Set pppres = Nothing
    Set ppapp = Nothing


    End Sub

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    You can only use insertfromfile to add a Sliderange not shapes and it returns the number of slides inserted (as an integer)

    Since your code is adding slides at the beginning and you know how many slides are being added (1 in all your examples) it should be easy to add shapes to the added slides.
    dim osld as slide
    Set osld=pppres.Slides(1)
    osld.Shapes ......
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    Dec 2016
    Posts
    2
    Location
    Mr. Wilson,

    Thanks for your help. I had put the line Set osld = pppres.slides(1) outside of the loop and that caused the error. This is fixed though. Thanks again!

Posting Permissions

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