Skip to main content

[archive] Check MS Word for "file already open"

  • March 23, 2010
  • 4 replies
  • 0 views

[Migrated content. Thread originally posted on 23 March 2010]

Our program checks to see if a file exists and then opens it with MS Word. If the file is already open, Word comes up with a dialog box. If the user clicks on Cancel, control returns to our program but we get an error that the command failed. I will try to attach a word document with the specific error/dialog box that we get.

I would like to know if there is a way to either (1) use C$FILEINFO or some other function to see if the file is already open or (2) intercept the error from MS Word. Following is an excerpt from the program.

* See if Word Doc already exists
MOVE RD-EVE-SEQ-NO TO EVENT-SEQUENCE.
STRING W-DOCKET-LOC DELIMITED BY SPACE,
WB-CASE-NBR DELIMITED BY SPACE,
".",
EVENT-SEQUENCE DELIMITED BY SPACE,
INTO DOCKET-FILE-NAME
END-STRING.
CALL "C$FILEINFO"
USING DOCKET-FILE-NAME, FILE-INFO,
GIVING STATUS-CODE.
* If file exists - Just open it
IF STATUS-CODE = ZERO
Perform Acu-Opening-Doc-Scrn
PERFORM 2700-OPEN-WORD-DOC THRU 2700-EXIT
Destroy Opening-Doc-HANDLE
GO TO 2000-EXIT
END-IF

2700-OPEN-WORD-DOC.
*Create application of word
CREATE Application OF Word
HANDLE IN wrdApp.

*Make WORD visible
MODIFY wrdApp @Visible = 1.

*Open the saved file
MODIFY wrdApp Documents::Open(
BY NAME @FileName DOCKET-FILE-NAME)
GIVING wrdDoc.

*Select the current document.
MODIFY wrdDoc @Select().
*Get the current selection of the document.
INQUIRE wrdApp Selection IN wrdSelection.

*Move to Top of document
MODIFY wrdDoc @Select()
INQUIRE wrdApp Selection IN wrdSelection
MODIFY wrdSelection GoTo(
BY NAME @What "3",
BY NAME @Which "1")
GIVING wrdRange.

2700-EXIT. EXIT.

4 replies

[Migrated content. Thread originally posted on 23 March 2010]

Our program checks to see if a file exists and then opens it with MS Word. If the file is already open, Word comes up with a dialog box. If the user clicks on Cancel, control returns to our program but we get an error that the command failed. I will try to attach a word document with the specific error/dialog box that we get.

I would like to know if there is a way to either (1) use C$FILEINFO or some other function to see if the file is already open or (2) intercept the error from MS Word. Following is an excerpt from the program.

* See if Word Doc already exists
MOVE RD-EVE-SEQ-NO TO EVENT-SEQUENCE.
STRING W-DOCKET-LOC DELIMITED BY SPACE,
WB-CASE-NBR DELIMITED BY SPACE,
".",
EVENT-SEQUENCE DELIMITED BY SPACE,
INTO DOCKET-FILE-NAME
END-STRING.
CALL "C$FILEINFO"
USING DOCKET-FILE-NAME, FILE-INFO,
GIVING STATUS-CODE.
* If file exists - Just open it
IF STATUS-CODE = ZERO
Perform Acu-Opening-Doc-Scrn
PERFORM 2700-OPEN-WORD-DOC THRU 2700-EXIT
Destroy Opening-Doc-HANDLE
GO TO 2000-EXIT
END-IF

2700-OPEN-WORD-DOC.
*Create application of word
CREATE Application OF Word
HANDLE IN wrdApp.

*Make WORD visible
MODIFY wrdApp @Visible = 1.

*Open the saved file
MODIFY wrdApp Documents::Open(
BY NAME @FileName DOCKET-FILE-NAME)
GIVING wrdDoc.

*Select the current document.
MODIFY wrdDoc @Select().
*Get the current selection of the document.
INQUIRE wrdApp Selection IN wrdSelection.

*Move to Top of document
MODIFY wrdDoc @Select()
INQUIRE wrdApp Selection IN wrdSelection
MODIFY wrdSelection GoTo(
BY NAME @What "3",
BY NAME @Which "1")
GIVING wrdRange.

2700-EXIT. EXIT.
Here is the dialog box and error that we recieve. Appreciate any help you can provide!

[Migrated content. Thread originally posted on 23 March 2010]

Our program checks to see if a file exists and then opens it with MS Word. If the file is already open, Word comes up with a dialog box. If the user clicks on Cancel, control returns to our program but we get an error that the command failed. I will try to attach a word document with the specific error/dialog box that we get.

I would like to know if there is a way to either (1) use C$FILEINFO or some other function to see if the file is already open or (2) intercept the error from MS Word. Following is an excerpt from the program.

* See if Word Doc already exists
MOVE RD-EVE-SEQ-NO TO EVENT-SEQUENCE.
STRING W-DOCKET-LOC DELIMITED BY SPACE,
WB-CASE-NBR DELIMITED BY SPACE,
".",
EVENT-SEQUENCE DELIMITED BY SPACE,
INTO DOCKET-FILE-NAME
END-STRING.
CALL "C$FILEINFO"
USING DOCKET-FILE-NAME, FILE-INFO,
GIVING STATUS-CODE.
* If file exists - Just open it
IF STATUS-CODE = ZERO
Perform Acu-Opening-Doc-Scrn
PERFORM 2700-OPEN-WORD-DOC THRU 2700-EXIT
Destroy Opening-Doc-HANDLE
GO TO 2000-EXIT
END-IF

2700-OPEN-WORD-DOC.
*Create application of word
CREATE Application OF Word
HANDLE IN wrdApp.

*Make WORD visible
MODIFY wrdApp @Visible = 1.

*Open the saved file
MODIFY wrdApp Documents::Open(
BY NAME @FileName DOCKET-FILE-NAME)
GIVING wrdDoc.

*Select the current document.
MODIFY wrdDoc @Select().
*Get the current selection of the document.
INQUIRE wrdApp Selection IN wrdSelection.

*Move to Top of document
MODIFY wrdDoc @Select()
INQUIRE wrdApp Selection IN wrdSelection
MODIFY wrdSelection GoTo(
BY NAME @What "3",
BY NAME @Which "1")
GIVING wrdRange.

2700-EXIT. EXIT.
Here is the dialog box and error that we recieve. Appreciate any help you can provide!

[Migrated content. Thread originally posted on 23 March 2010]

Our program checks to see if a file exists and then opens it with MS Word. If the file is already open, Word comes up with a dialog box. If the user clicks on Cancel, control returns to our program but we get an error that the command failed. I will try to attach a word document with the specific error/dialog box that we get.

I would like to know if there is a way to either (1) use C$FILEINFO or some other function to see if the file is already open or (2) intercept the error from MS Word. Following is an excerpt from the program.

* See if Word Doc already exists
MOVE RD-EVE-SEQ-NO TO EVENT-SEQUENCE.
STRING W-DOCKET-LOC DELIMITED BY SPACE,
WB-CASE-NBR DELIMITED BY SPACE,
".",
EVENT-SEQUENCE DELIMITED BY SPACE,
INTO DOCKET-FILE-NAME
END-STRING.
CALL "C$FILEINFO"
USING DOCKET-FILE-NAME, FILE-INFO,
GIVING STATUS-CODE.
* If file exists - Just open it
IF STATUS-CODE = ZERO
Perform Acu-Opening-Doc-Scrn
PERFORM 2700-OPEN-WORD-DOC THRU 2700-EXIT
Destroy Opening-Doc-HANDLE
GO TO 2000-EXIT
END-IF

2700-OPEN-WORD-DOC.
*Create application of word
CREATE Application OF Word
HANDLE IN wrdApp.

*Make WORD visible
MODIFY wrdApp @Visible = 1.

*Open the saved file
MODIFY wrdApp Documents::Open(
BY NAME @FileName DOCKET-FILE-NAME)
GIVING wrdDoc.

*Select the current document.
MODIFY wrdDoc @Select().
*Get the current selection of the document.
INQUIRE wrdApp Selection IN wrdSelection.

*Move to Top of document
MODIFY wrdDoc @Select()
INQUIRE wrdApp Selection IN wrdSelection
MODIFY wrdSelection GoTo(
BY NAME @What "3",
BY NAME @Which "1")
GIVING wrdRange.

2700-EXIT. EXIT.
Here is the dialog box and error that we recieve. Appreciate any help you can provide!

[Migrated content. Thread originally posted on 23 March 2010]

Our program checks to see if a file exists and then opens it with MS Word. If the file is already open, Word comes up with a dialog box. If the user clicks on Cancel, control returns to our program but we get an error that the command failed. I will try to attach a word document with the specific error/dialog box that we get.

I would like to know if there is a way to either (1) use C$FILEINFO or some other function to see if the file is already open or (2) intercept the error from MS Word. Following is an excerpt from the program.

* See if Word Doc already exists
MOVE RD-EVE-SEQ-NO TO EVENT-SEQUENCE.
STRING W-DOCKET-LOC DELIMITED BY SPACE,
WB-CASE-NBR DELIMITED BY SPACE,
".",
EVENT-SEQUENCE DELIMITED BY SPACE,
INTO DOCKET-FILE-NAME
END-STRING.
CALL "C$FILEINFO"
USING DOCKET-FILE-NAME, FILE-INFO,
GIVING STATUS-CODE.
* If file exists - Just open it
IF STATUS-CODE = ZERO
Perform Acu-Opening-Doc-Scrn
PERFORM 2700-OPEN-WORD-DOC THRU 2700-EXIT
Destroy Opening-Doc-HANDLE
GO TO 2000-EXIT
END-IF

2700-OPEN-WORD-DOC.
*Create application of word
CREATE Application OF Word
HANDLE IN wrdApp.

*Make WORD visible
MODIFY wrdApp @Visible = 1.

*Open the saved file
MODIFY wrdApp Documents::Open(
BY NAME @FileName DOCKET-FILE-NAME)
GIVING wrdDoc.

*Select the current document.
MODIFY wrdDoc @Select().
*Get the current selection of the document.
INQUIRE wrdApp Selection IN wrdSelection.

*Move to Top of document
MODIFY wrdDoc @Select()
INQUIRE wrdApp Selection IN wrdSelection
MODIFY wrdSelection GoTo(
BY NAME @What "3",
BY NAME @Which "1")
GIVING wrdRange.

2700-EXIT. EXIT.
I'm not sure how to see if the file is already in use, but you can prevent the runtime from stopping by using logic in the declarative section, such as:

OBJECT-EXCEPTION-HANDLING SECTION.
  USE AFTER EXCEPTION ON OBJECT.
OBJECT-EXCEPTION-HANDLER.
  CALL "C$EXCEPINFO" USING ERROR-INFO, WS-ERR-SOURCE,
  WS-ERR-DESCRIPTION.
After this, you can use the results to display a message or whatever you'd like.