Hello Peter,

If you look at the code in the Word test you will notice that the test firstly
- creates a new Word instance,
- makes it visible to the end user,
- then adds an empty document to the documents collection with the text "Hello from Pharo!"
- then it tests whether it can receive the same text back from Word.

After that, the test
- adds a new empty document to the documents collection with the text "Hello from Pharo! Some additional text. ", this time as an array of two texts - it activates this second document (this imitates the end user's window activation on the desktop)
- then it tests whether it can receive the same text back from Word.

If you look at the Task Manager, you'll notice that you have one Word process with two open documents:


Namely, for each document Word creates a new, separate window - the documents are not displayed in one "Word application window", but separately - that's a normal behavior for some versions of MS Office, and it happens also if you open several documents directly in Word. So, there is just one Word instance.

'finalize' clears the references to the Word instance, it doesn't close the program by itself. If you want to do that, you can send Quit message to Word before you destroy the reference (https://docs.microsoft.com/en-us/office/vba/api/word.application.quit(method)).

Similar behaviour is with Outlook, here's one example: https://www.excelcommand.com/excel-help/excel-how-to.php?i=124116

The calling among COM objects is asynchronous, and it's usually wise to wrap it in error handling structures.

Please tell us how it goes.

Best wishes,
Tomaz








------ Original Message ------
From: "PBKResearch" <pe...@pbkresearch.co.uk>
To: "Any question about pharo is welcome" <pharo-users@lists.pharo.org>
Sent: 5.4.2020 23:18:02
Subject: Re: [Pharo-users] Automation of MS Office from Pharo

Pablo - a final update before I close for the night. The Word test on the pharo 
8 version comes up green. The strange error message is nowhere to be seen in 
any Pharo 8 runs. The result is not what I expected; I finish up with two Word 
documents open, one with the first message, the other with the two messages. I 
thought the 'finalize' command would close it down.

Anyway, it looks as if I need to switch to P8 to use Pharo-Com. I shall 
continue testing tomorrow on P8.

Sorry for the late-night hassle.

Peter

Reply via email to