Microsoft Word - How to invoke

0 Likes

Problem:

How to invoke WORD and show it on the screen.

Resolution:

There are many things we can do with WORD but usualy we will want to invoke it, show it on the screen and open a file and start working with it, this is easily done following these steps.

Create a WORD.DEF file using the utility axdefgen.

Use the following word sample code :

       IDENTIFICATION         &nbs p;    DIVISION.

       PROGRAM-ID. TestWord.

       ENVIRONMENT          & nbsp;      DIVISION.

       CONFIGURATION         &nbsp ;     SECTION.

       SPECIAL-NAMES.

           SYSERR IS SYSERR

           copy "MSWORD.DEF". .

       DATA           &n bsp;           DIVISION.

       WORKING-STORAGE         &nb sp;   SECTION.

          COPY "activex.def".

          COPY "crtvars.def".

       01  WORD-HANDLES.

           03 wrdApp                HANDLE OF Application.

           03 wrdDoc                HANDLE OF Document.

           03 wrdSelection          HANDLE OF Selection.

       77  WORD-CLOSED       &nbsp ;      PIC 9.

       77  DOC-IS-SAVED       &nbs p;     PIC 9.

       77  DISP-EVENT                PIC Z(7)9.

       78  MSG-AX-EVENT       &nbs p;     VALUE 16436.

       78  EVENT-ACTION-COMPLETE    VALUE 5.

       

       PROCEDURE DIVISION.

       MAIN-APP.

           CREATE  Application OF Word HANDLE IN WrdApp

                    EVENT PROCEDURE IS WORD-EVENT.

           MODIFY  WrdApp            Documents::Add()

                    GIVING           wrdDoc.

           MODIFY  WrdApp            @Visible = 1.

           INITIALIZE      &n bsp;        WORD-CLOSED.

           PERFORM UNTIL            WORD-CLOSED = 1

                    ACCEPT           OMITTED BEFORE TIME 100

           END-PERFORM.

           DESTROY wrdSelection.

           DESTROY WrdDoc.

           DESTROY WrdApp.

           STOP    RUN.

       

       WORD-EVENT.

           IF      EVENT-TYPE        = MSG-AX-EVENT

                    IF EVENT-DATA-2  = @ApplicationQuit

                                     MOVE 1 TO WORD-CLOSED

                    ELSE IF EVENT-DATA-2  =

                            @ApplicationDocumentBeforeClose

                                     CALL "C$GETEVENTDATA" USING

                                       &nb sp;  EVENT-CONTROL-HANDLE

                                       &nb sp;  WrdDoc

                                       &nb sp;  DOC-IS-SAVED

                                       &nb sp;  END-CALL

                                     INQUIRE wrdDoc Saved in DOC-IS-SAVED

                                     IF DOC-IS-SAVED = 1

                                       &nb sp;MOVE 0 TO DOC-IS-SAVED

                                     ELSE

                                       &nb sp;MOVE 1 TO DOC-IS-SAVED

                                       &nb sp;END-IF

                                     CALL "C$SETEVENTDATA" USING

                                       &nb sp;  EVENT-CONTROL-HANDLE

                                       &nb sp;  wrdDoc

                                       &nb sp;  DOC-IS-SAVED

                                       &nb sp;  END-CALL

                                     MOVE EVENT-ACTION-COMPLETE TO

                                       &nb sp;  EVENT-ACTION

                    ELSE

                                     MOVE EVENT-DATA-2 TO DISP-EVENT

                                     DISPLAY "Word Event:" DISP-EVENT

                                       &nb sp;  UPON SYSERR

                    END-IF

           END-IF.

       SUB-EXIT.

           EXIT.  

      

Old KB# 2741
Comment List
Anonymous
Related Discussions
Recommended