You are currently offline, waiting for your internet to reconnect

How to automate PowerPoint by using Visual Basic in Office 2003, in Office XP Developer, and in Office 2000 Developer

Support for Office 2003 has ended

Microsoft ended support for Office 2003 on April 8, 2014. This change has affected your software updates and security options. Learn what this means for you and how to stay protected.

This article was previously published under Q222929
This article has been archived. It is offered "as is" and will no longer be updated.
This article describes how to automate Microsoft PowerPoint by using Microsoft Visual Basic in Microsoft Office 2003, in Microsoft Office XP Developer, and in Microsoft Office 2000 Developer.
By using automation in PowerPoint, you can programmatically print, display slides, and do most of the things you can do interactively. Follow these steps to build and run a Visual Basic automation example:
  1. Create a new Standard EXE project. Form1 is created by default.
  2. Add a CommandButton to the default form.
  3. From the Project menu, click References, and add Microsoft PowerPoint 8.0 Object Library and Microsoft Office 8.0 Object Library. For Office 2000, this is the 9.0 version of the Type Libraries. For Office 2002, this is the 10.0 version. For Microsoft Office 2003, this is the 11.0 version.
  4. Add the following to your form code window:
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub Command1_Click()    ' Start PowerPoint.    Dim ppApp As PowerPoint.Application    Set ppApp = CreateObject("Powerpoint.Application")     ' Make it visible.    ppApp.Visible = True     ' Add a new presentation.    Dim ppPres As PowerPoint.Presentation    Set ppPres = ppApp.Presentations.Add(msoTrue)     ' Add a new slide.    Dim ppSlide1 As PowerPoint.Slide    Set ppSlide1 = ppPres.Slides.Add(1, ppLayoutText)     ' Add some text.    ppSlide1.Shapes(1).TextFrame.TextRange.Text = "My first slide"    ppSlide1.Shapes(2).TextFrame.TextRange.Text = "Automating Powerpoint is easy" & vbCr & "Using Visual Basic is fun!"     ' Add another slide, with a chart.    Dim ppSlide2 As PowerPoint.Slide    Set ppSlide2 = ppPres.Slides.Add(2, ppLayoutTextAndChart)        ' Add some text.    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!"     ' Add a chart in the same location as the old one.    Dim cTop As Double    Dim cWidth As Double    Dim cHeight As Double    Dim cLeft As Double    With ppSlide2.Shapes(3)        cTop = .Top        cWidth = .Width        cHeight = .Height        cLeft = .Left        .Delete    End With    ppSlide2.Shapes.AddOLEObject cLeft, cTop, cWidth, cHeight, "MSGraph.Chart"     ' Add another slide, with an organization chart.    Dim ppSlide3 As PowerPoint.Slide    Set ppSlide3 = ppPres.Slides.Add(3, ppLayoutOrgchart)     ' Add some text.    ppSlide3.Shapes(1).TextFrame.TextRange.Text = "The rest is only limited by your Imagination"     ' Add an Org Chart in the same location as the old one.    With ppSlide3.Shapes(2)        cTop = .Top        cWidth = .Width        cHeight = .Height        cLeft = .Left        .Delete    End With    ppSlide3.Shapes.AddOLEObject cLeft, cTop, cWidth, cHeight, "OrgPlusWOPX.4" 'OrgPlusWOPX.4     ' is an object of the application Microsoft Organization Chart     ' Setup slide show properties.    With ppPres.Slides.Range.SlideShowTransition        .EntryEffect = ppEffectRandom        .AdvanceOnTime = msoTrue        .AdvanceTime = 5 ' 5 seconds per slide    End With     ' Prepare and run the slide show.    With ppPres.SlideShowSettings        .ShowType = ppShowTypeKiosk        .LoopUntilStopped = msoTrue        .RangeType = ppShowAll        .AdvanceMode = ppSlideShowUseSlideTimings        .Run    End With     ' Sleep so user can watch the show.    Sleep (15000)     ' Clean up.    ppApp.QuitEnd Sub					
  5. Run the project.
For more information about Office Automation, visit the Microsoft Office Development support Web site:

Article ID: 222929 - Last Review: 12/05/2015 13:28:18 - Revision: 5.4

  • Microsoft Office 2003, All Editions
  • Microsoft Office XP Developer Edition
  • Microsoft Office 2000 Developer Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Office PowerPoint 2003
  • Microsoft PowerPoint 2002 Standard Edition
  • Microsoft PowerPoint 2000 Standard Edition
  • Microsoft PowerPoint 97 Standard Edition
  • kbnosurvey kbarchive kbautomation kbhowto KB222929
  • © 2015 Microsoft