PowerPointApplication

From Xojo Documentation

Class (inherits from OLEObject)


Used to automate Microsoft PowerPoint. Supported on the Windows platform only.

Notes

fa-info-circle-32.png
You will need to copy the MSOfficeAutomation plugin (located in the Extras folder of the installation) to the Plugins folder before you can use this class.

The language that you use to automate Microsoft Office applications is documented by Microsoft and numerous third-party books on Visual Basic for Applications (VBA). Microsoft Office applications provide online help for VBA.

In Office 2007, click the Microsoft Office button and then click Options. Then select Popular and select the Show Developer Tab in the Ribbon checkbox.

You will then see a Visual Basic button in the Code group in the ribbon and menubar now includes a Help menu which leads to the VB online help.

To access the online help in Office 2003, choose Macros from the Tools Menu of your MS Office application, and then choose Visual Basic Editor from the Macros submenu. When the Visual Basic editor appears, choose Microsoft Visual Basic Help from the Help menu. The help is contextual in the sense that it provides information on automating the Office application from which you launched the Visual Basic editor.

If VBA Help does not appear, you will need to install the help files. Windows Office 2003 prompts you to install the VBA help files when you first request VBA help. You don't need the master CD.

Microsoft has additional information on VBA at http://msdn.microsoft.com/vbasic/ and have published their own language references on VBA. One of several third-party books on VBA is "VB & VBA in a Nutshell: The Language" by Paul Lomax (ISBN: 1-56592-358-8).

Sample Code

This code creates a PowerPoint document with a title page that contains a couple of bulleted items. The code is in the Action event handler of a Pushbutton.

Dim ppApp As New PowerPointApplication
Dim ppPres As PowerPointPresentation
Dim ppSlide1 As PowerPointSlide
Dim ppSlide2 As PowerPointSlide

ppPres = ppApp.Presentations.Add
ppSlide1 = ppPres.Slides.Add(1, Office.ppLayoutText)
ppSlide2 = ppPres.Slides.Add(2, Office.ppLayoutTextAndChart)

ppSlide1.Shapes(1).TextFrame.TextRange.Text = "My first slide"
ppSlide1.Shapes(2).TextFrame.TextRange.Text = "Automating PowerPoint is"_
+ " easy!"

ppSlide2.Shapes(1).TextFrame.TextRange.Text = "Slide 2's topic"
ppSlide2.Shapes(2).TextFrame.TextRange.Text = "You can create and use"_
+ " charts in your Powerpoint slides!"

// Setup slide show properties
ppPres.Slides.Range.SlideShowTransition.EntryEffect = Office.ppEffectRandom
ppPres.Slides.Range.SlideShowTransition.AdvanceOnTime = Office.msoTrue
ppPres.Slides.Range.SlideShowTransition.AdvanceTime = 3 // 3 seconds per slide

// Prepare and run the slide show
ppPres.SlideShowSettings.ShowType = Office.ppShowTypeKiosk
ppPres.SlideShowSettings.LoopUntilStopped = Office.msoTrue

ppPres.SlideShowSettings.RangeType = Office.ppShowAll
ppPres.SlideShowSettings.AdvanceMode = Office.ppSlideShowUseSlideTimings
ppPres.SlideShowSettings.Run

// Sleep 10 seconds so user can watch the show.
Dim t As Integer = ticks
Do
Loop Until ticks - t > 60 * 10

ppPres.Close

// Clean up.
ppApp.Quit

Exception err As OLEException
MsgBox(err.Message)

This code creates a new PowerPoint document and adds a picture to the first page. The path to the picture should be in the TextField, PictureField.

Dim ppApp As New PowerPointApplication
Dim ppPres As PowerPointPresentation
Dim ppSlide1 As PowerPointSlide

ppApp.Visible = True
ppPres = ppApp.Presentations.Add
ppSlide1 = ppPres.Slides.Add(1, Office.ppLayoutText)

// PictureField is a TextField that should contain a path to the picture
// to be added to PP title page.

If PictureField.Text <> "" Then
ppSlide1.Shapes.AddPicture(PictureField.Text, False, True, 10, 10)
Else
MsgBox("Please select a picture.")
End If

Exception err As OLEException
MsgBox(err.message)

See Also

UserGuide:Office Automation Overview, ExcelApplication, Office, OLEException, OLEObject, WordApplication classes.