Close a document from a Progress program ??

WayneFrank

Member
In a Progress program, I save a Word document (from a merge)

chWord:ActiveDocument:SaveAs( file-name-var )

Now this Word document is open on my PC. Is there a way that from the Progress program that I can close this document?

Thanks


DEFINE VARIABLE chWordApp AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chDoc AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chMerge AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chNewDoc AS COM-HANDLE NO-UNDO.


DEFINE VARIABLE chSavedDoc AS COM-HANDLE NO-UNDO.

&GLOBAL-DEFINE wdSendToNewDocument 0

CREATE "Word.Application" chWordApp.
chWordApp:ScreenUpdating = TRUE.
chWordApp:visible = FALSE.
chWordApp:displayAlerts = FALSE.

/* open the template document */
chDoc = chWordApp:documents:OPEN(merge-form,,YES,FALSE).
/* set Mail Merge object */
chMerge = chDoc:MailMerge.
/* open the data source */
chMerge:OpenDataSource(input-file).
/* set merge file to correct type */
chMerge:MainDocumentType = merge-file-type.
chMerge:SuppressBlankLines = FALSE.
/* merge target is a NEW word Doc */
chMerge:Destination = {&wdSendToNewDocument}.
/* Run merge */
chMerge:EXECUTE.
/* Close merge form */
chdoc:CLOSE(FALSE).

/* get handle to new document (the merged one) */
chNewDoc = chWordApp:ActiveDocument.
chNewDoc:fields:update.

chWordApp:visible = TRUE.

chWordApp:ACTIVATE.

/* Brian from Progress. */
RELEASE OBJECT chDoc.
RELEASE OBJECT chMerge.

/* SCIS 855 */
IF Type-9-Y-N = "Y"
THEN DO:
chWordApp:ActiveDocument:SaveAs( "C:\Windows\Temp\list.docx" ).
END.
RELEASE OBJECT chNewDoc.
RELEASE OBJECT chWordApp.
 

Osborne

Active Member
Either of these should do what you require:
Code:
chNewDoc:Close(FALSE).
/* or */
chWordApp:ActiveDocument:Close(FALSE).
 

WayneFrank

Member
Either of these should do what you require:
Code:
chNewDoc:Close(FALSE).
/* or */
chWordApp:ActiveDocument:Close(FALSE).
I am sorry to say that neither of these actually closes the saved document. What they do is leave another instance of word running with nothing open in it. (If that gives you any kind of clue.)

Any other ideas? Thx
 

Osborne

Active Member
Oh I see, and I presume chWordApp:Quit will be no good as it closes the whole lot?

What about either of these?:
chWordApp:Documents:Close(FALSE) NO-ERROR. /* chWordApp + ":" + Documents */
chWordApp:ActiveWindow:Close.
 
Last edited:

WayneFrank

Member
Oh I see, and I presume chWordApp:Quit will be no good as it closes the whole lot?

What about either of these?:
chWordApp:Documents:Close(FALSE) NO-ERROR. /* chWordApp + ":" + Documents */
chWordApp:ActiveWindow:Close.
Sorry to say, none of these work either.
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
In a Progress program, I save a Word document (from a merge)

chWord:ActiveDocument:SaveAs( file-name-var )

Well, you might be saving the document. Your SaveAs method is wrapped in a condition. Based on the code you've shared I don't know when the condition is met.

Now this Word document is open on my PC. Is there a way that from the Progress program that I can close this document?

Yes. If chWordApp:ActiveDocument (aka chNewDoc) is the handle to the document you want to close then you should be able to use its Close method to close the document. What have you tried?
 

WayneFrank

Member
I know it is saving the document because the document saved under that name is open on my PC.

It would be better if the user did not have to close the document. It is used in creating another merge document, all of which needs to be a transparent to the user as possible.

I have tried:
chWordApp:Quit
chWordAppocuments:Close(FALSE)
chWordApp:ActiveWindow:Close
chNewDoc:Close(FALSE).
chWordApp:ActiveDocument:Close(FALSE).

Thanks.
 

TomBascom

Curmudgeon
Do you have your RELEASE OBJECT bits in the right place? Doesn't chMerge need to be closed and cleaned up as well before you start in on a new task?
 

TomBascom

Curmudgeon
Who gave it to you? That would seem like a good person to be asking.

You may have noticed I'm not really much of a Windows guy? I certainly don't know squat about mail merge with Word.

But if I were coding something like this I would expect the logic to close the merge handle as well as the document handle and delete all of the handles used in phase 1 before I started creating new handles and preparing phase 2.

I suggest that you remove the bits after /* get handle to new document (the merged one) */ and focus on getting the document properly closed and cleaning up the handles. Once that is done go back to opening the new document and doing what ever needs to be done with it.

I also suggest that you put this code in its own procedures (one for phase 1, another for phase2) and that you create an unnamed widget pool for each procedure. That should help with handle management problems.
 
Top