Highlighted
Absent Member.
Absent Member.
843 views

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

[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.
0 Likes
2 Replies
Highlighted
Absent Member.
Absent Member.

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

Here is the dialog box and error that we recieve. Appreciate any help you can provide!
0 Likes
Highlighted
Absent Member.
Absent Member.

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

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.
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.