AW: Closing a Microsoft Word document

Rudolf Bargholz rudolf at bargholz.ch
Tue Mar 3 12:55:11 EST 2015


Hi Dawid,

If I recall correctly you have to manually ensure that all, and by all I mean every single reference to any object you created in the word document is explicitly destructed.

We use the following for Excel, which is similar to working with Word:

Calculate iWorkSheetObj as #NULL

Calculate lCloseFlag as kFalse
Calculate lTryCloseNo as 0
While not(lCloseFlag)&lTryCloseNo<3
Do iWorkBookObj.$::close(0) Returns lCloseFlag     ;; close the current excel work book without saving
If not(lCloseFlag)
Do iWorkBookObj.$::close() Returns lCloseFlag
End If
Calculate lTryCloseNo as lTryCloseNo+1
Calculate lCloseFlag as pick(isnull(lCloseFlag),lCloseFlag,kFalse)
End While

Calculate iWorkBookObj as #NULL
Do iExcelWorkBooksObj.$::close()
Calculate iExcelWorkBooksObj as #NULL
Do iExcelObj.$quit() Returns lErr     ;; close excel
Do iExcelObj.$release() Returns lErr     ;; close excel
Calculate iExcelObj as #NULL

Perhaps this will give you an idea what to do in your case.

Regards

Rudolf

-----Ursprüngliche Nachricht-----
Von: omnisdev-en-bounces at lists.omnis-dev.com [mailto:omnisdev-en-bounces at lists.omnis-dev.com] Im Auftrag von Dawid Mocke
Gesendet: Dienstag, 3. März 2015 18:41
An: OmnisDev List - English
Betreff: Closing a Microsoft Word document

Hi Guys,
I have successfully integrated to MS Word some years ago, but have never
been able to actually close a document.  So I open a template, save it as
something else and then merge the new document.
I have tried a couple of times to close the template, but never got it
working.
Now I have a situation where I have to generate a lot of documents in quick
succesession and while the original template is open, Microsoft will ask
you everytime if you want to open a 'Read-Only' copy, or replace, etc.

As you can understand this is both time consuming and very irritating.

This is the code I use to open the template:
Do iWordDocObjCollection.$open(iWordTempPath,kFalse,kFalse,kTrue) Returns
iWordDocObj     ;; open template file

To save the document as something else:
Do iWordDocObj.$SaveAs(iWordDocPath) Returns #F

Then I try and close the original template and I have tried the following
with no success:
Do iWordDocObj.$::close(iWordTempPath) Returns #F
Do iWordDocObj.$close(iWordTempPath) Returns #F

Any ideas that I can try?

thank you,

-- 
Dawid Mocke
This message (and any associated files) is intended only for the use of the
individual or entity to which it is addressed and may contain information
that is confidential, subject to copyright or constitutes a trade secret.
If you are not the intended recipient you are hereby notified that any
dissemination, copying or distribution of this message, or files associated
with this message, is strictly prohibited. If you have received this
message in error, please notify us immediately by replying to the message
and deleting it from your computer.
_____________________________________________________________
Manage your list subscriptions at http://lists.omnis-dev.com


More information about the omnisdev-en mailing list