Tested on winxp and word 2007 only
Pablo César may further upgrade / modify
Code: Select all
// bpd2000
// THIS EXAMPLE IS NEARLY FINISHED
//http://cuinl.tripod.com/Tips/off5.htm // based on this
//http://www.contactez.net/support/vbscript.html
//https://www.foxite.com/archives/word-spell-check-0000139859.htm
#include "hmg.ch"
#xcommand TRY => bError := errorBlock( {|oErr| break( oErr ) } ) ;;
BEGIN SEQUENCE
#xcommand CATCH [<!oErr!>] => errorBlock( bError ) ;;
RECOVER [USING <oErr>] <-oErr-> ;;
errorBlock( bError )
#xcommand FINALLY => ALWAYS
STATIC oWord
FUNCTION main()
LOCAL cText := "Wouldd you be soo kind to showa us how to usea the word spelll checker with HMG. Thank's in advaance."
MsgInfo(SpellCheck(cText),"Grammar Check")
RETURN nil
***********
STATIC FUNCTION SpellCheck(Texto)
LOCAL oDoc,oTexto
LOCAL cText:=Texto
LOCAL lOldGramm
LOCAL lOldUpper
IF .NOT. IsWord()
MsgInfo("MS Word is not installed in your computer.")
RETURN .F.
ENDIF
oWord := CreateObject( "Word.Application" )
oWord:Visible := .F.
oWord:Documents:Add()
oWord:Selection()
oWord:Selection:TypeText(cText)
lOldGramm := oWord:Options:CheckGrammarAsYouType()
oWord:Options:CheckGrammarWithSpelling := .F.
lOldUpper := oWord:Options:IgnoreUppercase()
oWord:Options:IgnoreUppercase := .F.
oWord:ActiveDocument:CheckSpelling()
oWord:Selection:WholeStory()
oWord:Selection:Copy()
cText := oWord:Selection:Text()
//‘Reset options and close everything
oWord:Options:CheckGrammarAsYouType := lOldGramm
oWord:Options:IgnoreUppercase := lOldUpper
oWord:ActiveDocument:Close(0)
oWord:Quit()
oWord := Nil
oTexto := NIL
oDoc := NIL
oWord := NIL
IF ! EMPTY(cText) // If ctext is empty that means that the process was canceled
Texto := cText
ENDIF
RETURN(Texto)
*************
FUNCTION isWord()
local lSuccess:=.F.
local oWord
TRY
oWord:= createObject("word.Application")
lSuccess:=.T.
CATCH
lSuccess:=.F.
END
RETURN lSuccess
***************