Visual Basic for Applications/PowerPoint

This lesson introduces PowerPoint macros.

Objectives and Skills edit

Objectives and skills for PowerPoint scripting include:

  • Using Microsoft PowerPoint objects

Readings edit

  1. Microsoft: AddSlide Method
  2. Microsoft: Shapes Property
  3. Microsoft: Built-In Document Properties

Multimedia edit

Examples edit

Presentations edit

'This macro inserts a slide and document properties at the end of the active presentation.

Option Explicit

Sub Presentations()
    Dim Slide As Slide
   
    Set Slide = ActivePresentation.Slides.Add( _
        ActivePresentation.Slides.Count + 1, ppLayoutText)
    Slide.Shapes(1).TextFrame.TextRange.Text = "Sample 11"
    Slide.Shapes(2).TextFrame.TextRange.Text = ActivePresentation.Name & vbCrLf & _
        ActivePresentation.BuiltInDocumentProperties("Author")
End Sub

Presentation Properties edit

' This macro displays a list of all available presentation property names.

Option Explicit

Sub PresentationProperties()
    Dim BuiltInDocumentProperties As Collection
    Dim Property As Object
    
    For Each Property In Application.ActivePresentation.BuiltInDocumentProperties
        Debug.Print Property.Name
    Next
End Sub

Activities edit

In these activities you will create macros which interact with PowerPoint presentations.

  1. Presentation Properties
    1. Create a macro that inserts a new text slide at the end of the active presentation and adds presentation information (properties) to the slide. You will need to refer to Slide.Shapes(1).TextFrame.TextRange.Text for the title text and Slide.Shapes(2).TextFrame.TextRange.Text for the content text. Concatenate vbCrLf to go to the next line of content. All of the information listed below is included in either Presentation properties directly or the BuiltInDocumentProperties. Your macro should include Option Explicit. Your inserted information should include the following.
      • Presentation Name
      • Path
      • Title
      • Subject
      • Author
      • Last Author
      • Revision Number
      • Creation Date
      • Total Editing Time
      • Number of Slides
      • Number of Hidden Slides
  2. Custom Footer
    1. Create a macro that Inserts a custom footer into the slide master for the active presentation. The footer should include a logo and company name on the left, and the current date on the right.
  3. Automatic Custom Footer
    1. Repeat Activity 2 inserting a custom footer into the slide master for the active presentation that includes a logo, company name, and current date. This time, implement the macro as an AutoOpen macro, and ensure that the macro tests to see if a footer is already in the presentation, and does nothing if a footer already exists.

See Also edit

References edit

  Type classification: this is a lesson resource.