PowerPoint API Reference

Explore the comprehensive Application Programming Interface (API) for Microsoft PowerPoint. This reference provides detailed information on objects, methods, properties, and events available for automating and extending PowerPoint functionality.

Key Concepts

Understanding these core concepts will help you effectively use the PowerPoint API:

Core Objects and Members

Object/Member Description Example Usage
Application Represents the PowerPoint application. Provides access to presentations, options, and events. PowerPoint.Application
Presentations A collection of all open Presentation objects. application.Presentations
Presentation Represents a single PowerPoint presentation file. application.ActivePresentation
Slides A collection of all Slide objects in a presentation. presentation.Slides
Slide Represents a single slide in a presentation. presentation.Slides.Item(1)
Shapes A collection of all Shape objects on a slide. slide.Shapes
Shape Represents a graphical object on a slide. slide.Shapes.AddTextbox(...)
TextFrame Contains the text properties of a shape. shape.TextFrame.TextRange.Text = "New Text"
TextRange Represents a sequence of characters within a TextFrame. textFrame.TextRange.Paragraphs(1).Text

Common Operations

Creating a New Presentation

Use the Add method of the Presentations collection to create a new presentation.

VBA Example:


Sub CreateNewPresentation()
    Dim pptApp As PowerPoint.Application
    Dim pptPres As PowerPoint.Presentation

    ' Get an instance of PowerPoint or create a new one
    On Error Resume Next
    Set pptApp = GetObject(, "PowerPoint.Application")
    If pptApp Is Nothing Then
        Set pptApp = New PowerPoint.Application
    End If
    On Error GoTo 0

    ' Make PowerPoint visible
    pptApp.Visible = True

    ' Add a new presentation
    Set pptPres = pptApp.Presentations.Add

    MsgBox "New presentation created!"
End Sub
            

Adding a Slide

Use the Add method of the Slides collection to add a new slide to the active presentation.

VBA Example:


Sub AddNewSlide()
    Dim pptPres As PowerPoint.Presentation
    Dim pptSlide As PowerPoint.Slide

    ' Ensure a presentation is open
    If PowerPoint.Application.Presentations.Count = 0 Then
        MsgBox "Please open or create a presentation first."
        Exit Sub
    End If

    Set pptPres = PowerPoint.Application.ActivePresentation

    ' Add a slide using a specific layout (e.g., ppLayoutText)
    ' You can find layout constants in the PowerPoint object model
    Set pptSlide = pptPres.Slides.Add(pptPres.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText)

    MsgBox "Slide added to the presentation."
End Sub
            

Adding Text to a Shape

You can add a textbox shape and then set its text content.

VBA Example:


Sub AddTextToSlide()
    Dim pptPres As PowerPoint.Presentation
    Dim pptSlide As PowerPoint.Slide
    Dim pptShape As PowerPoint.Shape
    Dim slideIndex As Integer

    ' Get the active presentation and a specific slide (e.g., the first slide)
    If PowerPoint.Application.Presentations.Count > 0 Then
        Set pptPres = PowerPoint.Application.ActivePresentation
        If pptPres.Slides.Count > 0 Then
            slideIndex = 1 ' Target the first slide
            Set pptSlide = pptPres.Slides(slideIndex)

            ' Add a textbox shape
            Set pptShape = pptSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 300, 50)

            ' Set the text of the textbox
            pptShape.TextFrame.TextRange.Text = "This text was added programmatically!"

            MsgBox "Text added to a shape on slide " & slideIndex & "."
        Else
            MsgBox "The active presentation has no slides."
        End If
    Else
        MsgBox "No presentation is open."
    End If
End Sub
            

API Navigation

Use the sidebar to navigate through different sections of the PowerPoint API, including specific object models, methods, and properties. You can also refer to the "Getting Started" and "Code Samples" sections for practical implementation guides.