Highlighted
Absent Member.
Absent Member.
470 views

[archive] Check user quit Excel

[Migrated content. Thread originally posted on 24 May 2007]

Hi all,

With ActiveX I open an Excel Document (visible). Excel document must be accessible for the user.
How can I check within the ACU program the user didn't quit the Excel document, preventing the cobol program will terminate with a connection error.

Thanx
0 Likes
2 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Check user quit Excel

Two alternatives. One is that you can turn of the Excel user interface, with the consequence that the user simply cannot do anything but see.
The other one is that you declare an event procedure, in which case you among other things will get notifications from Excel if the user try to quit the app. Now, I used to have an example of this around. I will see if I can find it and let you know.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Check user quit Excel

Here is an example I had, that illustrates running MS Word and controlling if the user terminates word. It was not Excel, but should be easy enough to port.

Gisle


       IDENTIFICATION              DIVISION.
       PROGRAM-ID. WordEvent.

       ENVIRONMENT                 DIVISION.
       CONFIGURATION               SECTION.
       SPECIAL-NAMES.
           copy "MSWORD.DEF".
                      .
       INPUT-OUTPUT                SECTION.
       FILE-CONTROL.
       DATA                        DIVISION.
       FILE                        SECTION.
       WORKING-STORAGE             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              PIC 9.
       77  DOC-IS-SAVED             PIC 9.
       77  DISP-EVENT               PIC Z(7)9.
       78  MSG-AX-EVENT             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               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
                                         EVENT-CONTROL-HANDLE
                                         WrdDoc
                                         DOC-IS-SAVED
                                         END-CALL
                                    INQUIRE wrdDoc Saved in DOC-IS-SAVED
                                    IF DOC-IS-SAVED = 1
                                       MOVE 0 TO DOC-IS-SAVED
                                    ELSE
                                       MOVE 1 TO DOC-IS-SAVED
                                       END-IF
                                    CALL "C$SETEVENTDATA" USING
                                         EVENT-CONTROL-HANDLE
                                         wrdDoc
                                         DOC-IS-SAVED
                                         END-CALL
                                    MOVE EVENT-ACTION-COMPLETE TO
                                         EVENT-ACTION
                   ELSE
                                    MOVE EVENT-DATA-2 TO DISP-EVENT
                                    DISPLAY "Word Event:" DISP-EVENT
                                         UPON SYSERR
                   END-IF
           END-IF.
       SUB-EXIT.
           EXIT.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.