Automatically run MS-Office application

zhaozj2021-02-16  55

Automatically run MS-Office application

By vgirish

This guide helps you learn the basis of automatic operation. With this code, you can control PowerPoint in your application.

You can update PowerPoint, open any show, to the slide you want to watch, run a slide show, and more.

By the same steps given below, you can automatically run Word, Excel, or any MS-Office application.

(1) Create an application-based dialog, in the third step of AppWizard, select the Automation check box.

(2) Creating a button for Start, Run, Close, First Slide, Last Slide, the Previous Slide, and Next Slide function, use the following functions.

(3) Add the following statement to the initInstance of your application:

// Initialize Ole Libraries

IF (! Afxoleinit ())

{

AFXMessageBox ("Failed to Initialize Ole);

Return False;

}

(4) In your dialog box, open ClassWizard, select the Automation tab, select Add Class -> from a type library., Then select MSPPT8.OLB from C: / Program Files / Microsoft Office / Office /.

(5) In the header file of your dialog, add a statement:

#include "msppt8.h"

(6) Add the following variables in your dialog box:

_Application App; // App is the powerpoint _application objectation Object

Presentations Presentations;

_Presentation Presentation;

SlideshowView view;

SlideshowWindow SlideshowWindow;

SlideshowSettings Slideshow;

Slides Slides;

_SLIDE SLIDE;

Let us now go to the PowerPoint application function.

(6) To start PowerPoint, you must write the following code in the Start function:

Void cpowerpntdlg :: OnbtnStart ()

{

// Start PowerPoint and Get Application Object ...

IF (! app.created "))))

{

AfxMessageBox ("COULDN'T Start PowerPoint.");

}

Else

{

// Make PowerPoint Visible and Display a Message

App.setvisible (TRUE);

Trace ("PowerPoint Is Running!");

}

}

(7) Open a display in the hard disk, add code to the Open button function call:

Void cpowerpntdlg :: OnbTnOpen ()

{

Static char based_code szfilter [] = "PowerPoint Files (* .ppt) | * .ppt ||"; CFiledialog Filedlg (True, "PPT", NULL, OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON | OFN_PATHMUSTEXIST, SZFILTER;

Filedlg.domodal ();

// TO GET The SELECTED File's Path and Name

CString strfilename;

Strfilename = filedlg.getpathname ();

IF (! strfilename.isempty ())

{

Presentations = app.getpresentations ();

Presentation = presentations.open (StrfileName, 0, 0, 1);

}

}

(8) To close PowerPoint, add code in a Close button function call:

Void cpowerpntdlg :: OnbtnClose ()

{

CaNexit ())

app.quit ();

}

The function in steps 7, 8, and 9 is that you need to know the basic processing of the application.

Now we have a powerpoint running and prepared, we need to do something like to run a slide show and perform other behaviors.

Now let's run the slide show.

(9) Add code to run the slide show, add code in the Run button function call:

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 ();

Slideshow.Run ();

}

(10) Sometimes, you may want to start all from the first slide. To the first slide you can use these code:

Void cpowerpntdlg :: Onbtnfirst ()

{

Presentation = app.getactivePresentation ();

SlideshowWindow = presentation.getslideshowWindow ();

View = slideeshowwindow.getView ();

View.first ();

}

(11) Similarly, to the last slide:

Void cpowerpntdlg :: onbtnlast ()

{

Presentation = app.getactivePresentation ();

SlideshowWindow = presentation.getslideshowWindow ();

View = slideeshowwindow.getView ();

VIEW.LAST ();

}

(12) Since you have a slide show, you obviously return to the previous slide on some point in time. To do this, use the following code:

void cpowerpntdlg :: Onbtnprevious ()

{

Presentation = app.getactivePresentation ();

SlideshowWindow = presentation.getslideshowWindow ();

View = slideeshowwindow.getView ();

View.previous ();

}

(13) Is it now interest to the next slide? In this case, this function will help you:

Void cpowerpntdlg :: onbtnnext ()

{

Presentation = app.getactivePresentation ();

SlideshowWindow = presentation.getslideshowWindow ();

View = slideeshowwindow.getView ();

View.next ();

}

This is, buddy. Check out available functions such as other transformations, animation production. You can do it in your own way.

This is the basic framework, you can see how easy it is to handle PowerPoint. It is also a thing on Word, Excel and other MS-Office. I wish you good luck and happiness!

转载请注明原文地址:https://www.9cbs.com/read-27776.html

New Post(0)