Visual Basic for Applications/PowerPoint

From Wikiversity
Jump to navigation Jump to search

This lesson introduces PowerPoint macros.

Objectives and Skills[edit | edit source]

Objectives and skills for PowerPoint scripting include:

  • Using Microsoft PowerPoint objects

Readings[edit | edit source]

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

Multimedia[edit | edit source]

Examples[edit | edit source]

Presentations[edit | edit source]

'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 & _
End Sub

Presentation Properties[edit | edit source]

' 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
End Sub

Activities[edit | edit source]

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 | edit source]

References[edit | edit source]

Nuvola apps edu miscellaneous.svg Type classification: this is a lesson resource.