Consulting

Results 1 to 2 of 2

Thread: VBA - Powerpoint Addtext in existing file

  1. #1
    VBAX Regular
    Joined
    Sep 2005
    Posts
    8
    Location

    VBA - Powerpoint Addtext in existing file

    Hello,

    I am just trying to ad a new slide plus some text to an exiting ppt file.
    I can't understand why this does not work.

    Please advise

    Thank you
    Kato01


    Sub writeToPPT()
    'Add a reference to Microsoft Powerpoint 12.0 object library

    Dim oPPTApp As PowerPoint.Application
    Dim oPPTFile As PowerPoint.Presentation
    Dim oPPTShape As PowerPoint.Shape
    Dim oPPTSlide As PowerPoint.Slide
    Set oPPTApp = CreateObject("PowerPoint.Application")
    oPPTApp.Visible = msoTrue
    'opening an existing presentation
    'Change the path and presentation name
    Set oPPTFile = oPPTApp.Presentations.Open(Filename:="Y:\D\(0)_OFFICE\MySimulations\My Simulations 20140204.pptM")
    oPPTFile.Slides.Add Index:=oPPTFile.Slides.Count + 1, Layout:=ppLayoutBlank
    NS = oPPTFile.Slides.Count
    'Write to the first shape on first slide
    Set oPPTShape = oPPTFile.Slides(2).Shapes(1)
    With oPPTShape.TextFrame.TextRange
    .Font.Size = 12
    .Font.Color = vbRed
    .Font.Underline = msoTrue
    .Text = "Add some sample text." & vbCrLf _
    & "Line 2 to add some more text" & vbCrLf _
    & "Line 3 to add even more text"

    End With
    'Add cleanup code
    End Sub

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Is this code running within PowerPoint or for example from Excel etc?
    Unless this is running outside PowerPoint there is no need for a reference or to create an application.

    The main problem though is that you are creating a blank slide (with no shapes) and trying to add to a non existant shape 1. (*assuming slides 2 is the added slide which it might not be as your code doesn't make a lot of sense.)
    Last edited by John Wilson; 03-11-2014 at 04:04 AM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Tags for this Thread

Posting Permissions

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