XL7: Visual Basic Example for Creating a PowerPoint Slide Show

Last reviewed: September 2, 1997
Article ID: Q139880
The information in this article applies to:
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft PowerPoint for Windows 95, version 7.0

SUMMARY

In Microsoft Excel, you can programmatically control Microsoft PowerPoint, with a Visual Basic for Applications macro that uses OLE automation. To use the properties and methods in the object library provided by PowerPoint, you will need to create an object variable using the CreateObject function. Also, if you are planning to use the built-in constants provided by the object library, you will need to make a reference to the library.

MORE INFORMATION

The following example creates a presentation, adds graphics and text, and then runs the slide show.

Microsoft provides examples of Visual Basic for applications procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.

To run the following macro you will need to perform the following steps:

  1. Open a new workbook and type the following macro code in a new module sheet:

       Sub PowerPointOLEAutomation()
       Dim PPT As Object
       Dim Pres As PowerPoint.Presentation
       Dim Slide1 As PowerPoint.Slide
       Dim Slide2 As PowerPoint.Slide
       Dim Slide3 As PowerPoint.Slide
       Dim Slide4 As PowerPoint.Slide
       Dim i as integer
    
       'creates the PowerPoint Object
       Set PPT = CreateObject("powerpoint.application.7")
       PPT.AppWindow.Visible = True 'Makes PowerPoint visible
    
       Set Pres = PPT.Presentations.Add 'Adds a blank presentation
    
       'adds a blank slide
       Set Slide1 = Pres.Slides.Add(1, ppLayoutBlank)
       Set Slide2 = Pres.Slides.Add(2, ppLayoutBlank)
       Set Slide3 = Pres.Slides.Add(3, ppLayoutBlank)
       Set Slide4 = Pres.Slides.Add(4, ppLayoutBlank)
    
       'you can use universal naming convention (UNC) to point to network share
       'adds a graphic image to the slide
       'these need to be on a separate line
       Slide1.Background.Fill.PresetShaded ppPresetShadeEarlySunset, 1, 1
       Slide2.Background.Fill.PresetShaded ppPresetShadeDaybreak, 1, 1
       Slide3.Background.Fill.PresetShaded ppPresetShadeMahogany, 1, 1
       Slide4.Background.Fill.PresetShaded ppPresetShadeNightfall, 1, 1
    
       For i = 1 To 4 'starts a FOR loop
    
           With Pres.Slides(i)
                   .Objects.AddTextFrame 5000, 0, 5000 'adds a text frame
                   Select Case i
                       Case 1
                           'enters text into the text frame
       .Objects(1).Text = "Today is " & _
       Format(Date, "mm/dd/yy")
                       Case 2
                           .Objects(1).Text = "This Is Just A Test"
                       Case 3
                          .Objects(1).Text = "Please Do Not Be Alarmed"
                       Case 4
                           .Objects(1).Text = "Everything Is OK"
                   End Select
    
                   'sets characteristics for the font
                   With .Objects(1).Text.Font
    
                       'screen measurements are done in Twips,
                       'multiply by 20 to get normal pixel size
                           .Size = 50 * 20
                           .Bold = ppTrue
                           .Shadow = ppTrue
                   End With
                   'center aligns the text
                   .Objects(1).Text.ParaFormat.Alignment = ppAlignCenter
    
           End With
       Next i
    
       'copies a chart
       ThisWorkbook.Worksheets(1).DrawingObjects("Chart 1").CopyPicture
    
       PPT.ActiveWindow.View.Paste 'pastes the chart
    
       'runs a Slide Show presentation
       Pres.SlideShow.Run (ppSlideShowFullScreen)
    
       'clears the object variable
       Set PPT = Nothing 'This does not close the application
    
       End Sub
    
    

  2. Create a reference to the PowerPoint object library by activating the module sheet that contains the macro. Click References on the Tools menu and select the PowerPoint 7.0 Object Library check box, then click OK.

  3. In Sheet1 of the workbook that contains the macro code, type the following:

          A1: 1
          A2: 2
          A3: 3
    

  4. Create any type of embedded chart on Sheet1 using the range of A1:A3 as the source data.

  5. Run the macro

REFERENCES

Getting Started Controlling Microsoft PowerPoint for Windows 95 Through OLE Automation - White Paper


Additional query words: 7.00 PUB_PP powerpt
Keywords : kbprg PgmHowTo xlwin kbcode kbhowto kbole kbprg
Version : 7.00
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.