Virtual Developer Workshop: Containerized Development with Docker

Environment: Tutorials, Microsoft Office


This tutorial helps you to learn the basics of automation. With this code, you can control PowerPoint from your application. You can open PowerPoint programmatically, open any presentation, go to any slide that you want to, run the slideshow, and so forth.

Steps to Follow

By following the same steps given below, you can automate Word, Excel, or any other Microsoft Office application.

  1. Create a dialog-based application and in the App Wizard's step 3 of 6, select the automation checkbox.
  2. Create buttons for Start, Run, Close, First Slide, Last Slide, Previous Slide, and Next Slide functions and use the following functions accordingly.
  3. In your application's InitInstance function, add the following lines:
  4.   // Initialize OLE libraries
      if (!AfxOleInit())
        AfxMessageBox("Failed to initialize OLE");
        return FALSE;
  5. In your dialog's class, open the class wizard, select the automation tab, select "Add Class" ... "From a type library", and then select msppt8.olb from "C:\Program Files\Microsoft Office\Office\".
  6. In your header file of your dialog, include the following line:
  7.   #include "msppt8.h"
  8. Add the following variables in your dialog's header file.
  9.   _Application app;    // app is the PowerPoint
                           // _Application object
      Presentations Presentations;
      _Presentation Presentation;
      SlideShowView View;
      SlideShowWindow SlideShowWindow;
      SlideShowSettings slideshow;
      Slides slides; 
      _Slide slide;
  10. To start PowerPoint, you have to write this code in the Start button's function.
  11.   void CPowerPntDlg::OnBtnStart()
        // Start PowerPoint and get Application object...
            AfxMessageBox("Couldn't start PowerPoint.");
        else    // Make PowerPoint visible and display a message
            TRACE("PowerPoint is Running!");
  12. To open a presentation from the hard disk, add this code in the Open button's function call.
  13.   void CPowerPntDlg::OnBtnOpen()
        static char BASED_CODE szFilter[] = "PowerPoint Files
        CFileDialog FileDlg(TRUE,"PPT",NULL,
        // To get the selected file's path and name
        CString strFileName;
        strFileName = FileDlg.GetPathName();
            Presentations = app.GetPresentations();
            Presentation  = Presentations.Open(strFileName,0,0,1);
  14. To close PowerPoint, add this code in the Close button's function call.
  15.   void CPowerPntDlg::OnBtnClose()
        if (CanExit())
  16. To run the slideshow, use this code in the Run button's function call
  17.   void CPowerPntDlg::OnBtnRun()
        Presentations = app.GetActivePresentation();
          slides      = Presentation.GetSlides();
         // Show the first slide of the presentation
        slide         = slides.Item(COleVariant((long)1));
        //Run the show
        slideshow     = Presentation.GetSlideShowSettings();
  18. Sometimes, you might want to start all over from the first slide. To go to the first slide, you can use this code:
  19.   void CPowerPntDlg::OnBtnFirst()
        Presentation    = app.GetActivePresentation();
        SlideShowWindow = Presentation.GetSlideShowWindow();
        View            = SlideShowWindow.GetView();
  20. And similarly, to go to the last slide
  21.   void CPowerPntDlg::OnBtnLast()
        Presentation    = app.GetActivePresentation();
        SlideShowWindow = Presentation.GetSlideShowWindow();
        View            = SlideShowWindow.GetView();
  22. Now that you have the slideshow running, you would obviously want to go to the previous slide at some point of time. To do just that, you can use this code:
  23.   void CPowerPntDlg::OnBtnPrevious()
        Presentation    = app.GetActivePresentation();
        SlideShowWindow = Presentation.GetSlideShowWindow();
        View            = SlideShowWindow.GetView();
  24. Interested in going to the next slide now? In that case, this function will help you:
  25.   void CPowerPntDlg::OnBtnNext()
        Presentation    = app.GetActivePresentation();
        SlideShowWindow = Presentation.GetSlideShowWindow();
        View            = SlideShowWindow.GetView();


That's it, folks. Check out the other functions available for transitions, animations, and so forth and you can go ahead on your own. This is the basic framework and you can see how easy it is to handle PowerPoint. It's the same case with Excel, Word, or any other Microsoft Office application. All luck to you and have a great time. You can also check out http://support.microsoft.com/default.aspx?scid=kb;en-us;Q178749 for more information.

I used this code to do remote PowerPoint presentations. The concept was to run a presentation at one place and the clients will be looking at it simultaneously from different places at the same time.


  • Add a command button to a slide and set it caption?

    Posted by hacaonguyen on 08/16/2005 12:46pm

    I added a command button to a slide as follow:
    //MyCode Begin
    oShape = oShapes.AddOLEObject(10, 10, 100, 50, "Forms.CommandButton.1", "", 0, "", 0, "", );
    //MyCode End
    But my broplem is I could not set caption and VB code for this button.
    I can do this in VB as below code:
    'MyCode in VB Begin
    Set oShape = oSlide.Shapes.AddOLEObject(200, 200, 100, 0, "Forms.CommandButton.1")
    oShape.OLEFormat.Object = True
    oShape.OLEFormat.Object.Name = "cmdRun" 'or oShape.Name = "cmdRun"
    oShape.OLEFormat.Object.Caption = "Run"
    Dim sCode As String
    sCode = "Private Sub " &
    oShape.OLEFormat.Object.Name & "_Click()" &
    vbCrLf & _
    " MsgBox ""You Clicked the
    CommandButton""" & vbCrLf & _
    "End Sub"
    (1).CodeModule.AddFromString sCode
    'MyCode in VB End
    Could any one help.
    Many thanks

  • In C++ how to detect an Automatic Date in a powerpoint slide?

    Posted by one_apple on 03/14/2005 10:26pm

    I will appreciate anybody's help on this: In C++ how to detect an Automatic Date in a powerpoint slide? Thanks

  • I have a problem

    Posted by Legacy on 02/06/2004 08:00am

    Originally posted by: Jenny

    Very cool your explanation, but nowdays we have another problem.
    U know all the Sun-Microsoft problem....
    From september on there will be no support anymore for the Java packages Microsoft created and that includes the ones used to automate Office. Please, tell me! How would be possible to automate it without using COM stuff, I mean without using the packages Microsoft created? Please, help me! I've been wondering around with no practical solution and u seem very practical!
    Thanx on advance!

  • how to create an acticex control and insert it to .ppt

    Posted by Legacy on 12/02/2003 08:00am

    Originally posted by: david

    i create my activex control,

    i use it in .htm correctly.

    now , i want to use my activex control in a .ppt file

    how can i do for this?

    please help me



  • a small question

    Posted by Legacy on 11/25/2003 08:00am

    Originally posted by: padma

    the article written by you is really good n helpful,but right now im interested to kno is .. is it possible to have it the other way round i.e. controlling an application(for e.g. an applet) through microsoft powerpoint??? plzzzzzzz do lemme kno abt the possibilities,if any..and the way to go about it. informaion provided on this matter will be greatly appreciated.

  • I Compliment You On Sharing

    Posted by Legacy on 08/26/2003 07:00am

    Originally posted by: Dave Busey

    Thank you for setting out such a nice tutorial. The code and explanations are going to save some of us a lot of time from reference searching and experimentation. I appreciate your generosity.

    Dave Busey

  • Great pice of work.

    Posted by Legacy on 08/22/2003 07:00am

    Originally posted by: Ilya Kalujny

    Could be really useful sometimes.

  • Cool, but is it possible to remote to another machine?

    Posted by Legacy on 08/20/2003 07:00am

    Originally posted by: Jackson Lee

    Your code works on the same machine, is it possible CreateDispatch on another machine?



  • Good info But.....

    Posted by Legacy on 08/19/2003 07:00am

    Originally posted by: one4all

    Good Article, but, I didn't understand why did you need this application for "Remote power presentation".
    You could have peacefully used Netmeeting right?

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date