invoking Microsoft Word (spelling)though Progress problem

Hi,

Windows XP, Progress Version 9.1e and Microsoft Word 2003

We have a system which uses a button to invoke Microsoft Word spelling module on an editor box. This has been working quite happily for a few years, until some PC's were upgraded to Vista with Microsoft Office Word 2007, and now when the spell check button is pressed the job just locks up.

I have enclosed the code snippet below, and if any one has any suggestions as what needs to be changed I would be grateful.

Mike

DEF VAR crowstate AS CHAR NO-UNDO.
DEF VAR hcontainer AS HANDLE NO-UNDO.
DEFINE VAR wordAppl AS COM-HANDLE NO-UNDO.
DEFINE VAR i AS INTEGER NO-UNDO.
DEF VAR oldtext LIKE EDITOR_booktext NO-UNDO.

/*
* First we need to determine if we are running on a system with Word for
* Office 95 or Office 97 since the Automation Objects are dramatically
* different. We do this by looking for a particular Object and if it fails
* then we try the other version. This is done by accessing the system
* registry
*/

LOAD "Word.Application" BASE-KEY "HKEY_CLASSES_ROOT" NO-ERROR. /* Open Registry key */
IF error-status:error THEN DO:

/* Office 95 Word
*
* When the Spell Check button is pressed, create an Automation Object
* for Word.Basic
*
* Copy the text from editor_booktext and put into a new file created in Word.
* The spelling check is done on that Word file and all changes are put
* into that unnamed file. This is all done by the ToolsSpelling() method.
*
* Once that completes, we take the updated contents of the unnamed file
* and copy it back into the edit control on the Progress frame. We then
* close the Automation Object without saving the file.
*/

CREATE "Word.Basic" wordAppl.
NO-RETURN-VALUE wordAppl:FileNew.
ASSIGN editor_booktext.
NO-RETURN-VALUE wordAppl:Insert(editor_booktext).
ASSIGN i = wordAppl:ToolsSpelling NO-ERROR.
NO-RETURN-VALUE wordAppl:AppHide("Microsoft Word").
NO-RETURN-VALUE wordAppl:EditSelectAll.
editor_booktext:SCREEN-VALUE = wordAppl:Selection().
NO-RETURN-VALUE wordAppl:FileClose(2).
NO-RETURN-VALUE wordAppl:AppClose("Microsoft Word").
END.

ELSE DO:
UNLOAD "Word.Application". /* Close Registry key */
/* Office 97 Word
*
* When the Spell Check button is pressed,create an Automation Object for
* Word.Application
*
* Copy the text from editor_booktext and put into a new document in an OLE
* Collection. The spelling check is done on that document and all
* changes are put into that document. This is all done by the
* CheckGrammar() method.
*
* Once that completes, we take the updated contents of the document
* and copy it back into the edit control on the Progress frame. We then
* quit the Automation Object.
*/

CREATE "Word.Application" wordAppl.
wordAppl:Documents:Add().
ASSIGN editor_booktext
oldtext = trim(EDITOR_booktext:SCREEN-VALUE).


wordAppl:Documents:Item(1):Range(0,0):InsertAfter(editor_booktext).
wordAppl:Options:CheckGrammarWithSpelling = TRUE.
wordAppl:Documents:Item(1):CheckGrammar().
wordAppl:Visible = FALSE.

PAUSE 0 NO-MESSAGE.
ASSIGN
editor_booktext:SCREEN-VALUE=wordAppl:Documents:Item(1):Range(0,wordAppl:Documents:Item(1):Characters:Count):Text.
editor_booktext:SCREEN-VALUE = TRIM(editor_booktext:SCREEN-VALUE).

wordAppl:Quit(0).
END.

RELEASE OBJECT wordAppl
.
 

Jupiter

Member
Hi Mike,

Just checked your code in Windows XP OS and with MS-Word 2007 and OE10.01B. This is working.

So the issue may lie with Windows Vista.

Regards
 

peststudio

New Member
I have the same problem and think its because the spell check box appears behind the progress program thats running so you can't see it and it seems like it locks up. Not sure how to bring the spell window to front. Any ideas?
 

Osborne

Active Member
I have WIndows Vista and running the code have the same problem.

Even though it appears to have locked up you can access the spell check box although not ideal at all. When running, if you hold down the Alt key it appears in the list of windows and can be selected and once selected everything is fine.

I don't know if this action can be coded in Progress.
 

Cringer

ProgressTalk.com Moderator
Staff member
I don't suppose, you can just MOVE-TO-BOTTOM on your application after you've invoked the spell check window? Haven't looked into it at all, but it might work...
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
I have seen this issue with a similar use case. Desktop window management changed pretty substantially between XP and Vista, so this is not unexpected.

This KB article may shed some light, and provide a workaround.
 

trx

Member
Maybe you just need to show Word after creating it.
Your code works with MS Word 2003, WIN7 64-bit, OE 10.1C (32-bit) with wordAppl:Visible = TRUE line and just hangs up without that line.
Code:
CREATE "Word.Application" wordAppl.
[B]wordAppl:Visible = TRUE.[/B]
ASSIGN editor_booktext
 

vickig

New Member
Thanks guys managed to fix it by using FindWindowA API and SetForegroundWindow API to move the spell check window on top of everything. Works really well if anyone else is having problems the window opening behind everything else.
 

dkellgren

Member
In definitions section:

DEFINE VARIABLE intResult AS INTEGER NO-UNDO.
DEFINE VARIABLE intHwnd AS INTEGER NO-UNDO.

PROCEDURE SetForegroundWindow EXTERNAL "USER32.DLL":
DEFINE INPUT PARAMETER intHwnd AS LONG.
DEFINE RETURN PARAMETER intResult AS LONG.
END PROCEDURE.

PROCEDURE FindWindowA EXTERNAL "USER32.DLL":
DEFINE INPUT PARAMETER intClassName AS LONG.
DEFINE INPUT PARAMETER chrCaption AS CHARACTER.
DEFINE RETURN PARAMETER intHandle AS LONG.
END PROCEDURE.

I have this code on a button trigger. It references a screen fill-in called scr-Note. The reference to "Document1 - Microsoft Word" should be changed though as the created Word document instance may not always be that title. In my specific case, it would be so I didn't code any further.

DEFINE VARIABLE oCorrection AS CHARACTER NO-UNDO.
DEFINE VARIABLE chWord AS COMPONENT-HANDLE NO-UNDO.

CREATE "Word.Application" chWord.
ASSIGN chWord:VISIBLE = NO.
chWord:DOCUMENTS:ADD().

RUN FindWindowA (0, "Document1 - Microsoft Word", OUTPUT intHwnd).
IF intHwnd <> 0 THEN
RUN SetForeGroundWindow(intHwnd, OUTPUT intResult).

chWord:DOCUMENTS:ITEM(1):RANGE(0,0):INSERTAFTER(scr-Note:screen-value).
chWord:DOCUMENTS:ITEM(1):CHECKSPELLING (?,NO,YES).
chWord:DOCUMENTS:ITEM(1):SELECT.

ASSIGN oCorrection = chWord:SELECTION:TEXT
oCorrection = SUBSTRING(oCorrection,1,LENGTH(oCorrection) - 1).

chWord:QUIT(0).
RELEASE OBJECT chWord.

scr-Note:SCREEN-VALUE = oCorrection.
 
Top