I needed a spell checker, but without displaying MSWord.
Here is the code, use it and change it as you wish...
------------------
Here is the code, use it and change it as you wish...
Code:
'--------------------------------------------------------------- 'Author: Peter Redei 'Date: 10/08/02 'Subject:SpellChecker without displaying MSWord '--------------------------------------------------------------- #COMPILE EXE #INCLUDE "oWord.inc" SUB Spell(sWord AS STRING, sSuggs() AS STRING) LOCAL oWordApp AS WordApplication DIM oSpellingSuggestions AS WordSpellingSuggestions ' Spelling Suggestions collection DIM oSpellingSuggestion AS WordSpellingSuggestion ' Spelling Suggestion class DIM vBool AS VARIANT DIM vVnt AS VARIANT DIM vText AS VARIANT DIM vRes AS VARIANT DIM suggs AS LONG DIM i AS LONG SET oWordApp = WordApplication IN "Word.Application" IF ISFALSE ISOBJECT(oWordApp) THEN _ SET oWordApp = NEW WordApplication IN "Word.Application" ' Could MSWORD be opened? If not we will not check the spelling IF ISTRUE ISOBJECT(oWordApp) THEN 'add a document LET vVnt = 0 OBJECT CALL oWordApp.Documents.Add TO vVnt LET vText = sWord LET vRes = 0 OBJECT CALL oWordApp.GetSpellingSuggestions(vText) TO vRes SET oSpellingSuggestions = vRes LET vBool = 0 OBJECT GET oSpellingSuggestions.Count TO vBool suggs = VARIANT#(vBool) IF suggs > 0 THEN REDIM sSuggs(1 TO suggs) FOR i = 1 TO suggs LET vVnt = i LET vRes = 0 OBJECT CALL oSpellingSuggestions.Item(vVnt) TO vRes SET oSpellingSuggestion = vRes LET vBool = 0 OBJECT GET oSpellingSuggestion.Name TO vBool sSuggs(i) = VARIANT$(vBool) NEXT END IF LET vVnt = 0 OBJECT CALL oWordApp.ActiveWindow.Close(vVnt) OBJECT CALL oWordApp.Quit SET oSpellingSuggestion = NOTHING SET oSpellingSuggestions = NOTHING END IF SET oWordApp = NOTHING END SUB FUNCTION PBMAIN() REDIM sSuggs(0) AS STRING Spell "Helo", sSuggs() IF UBOUND(sSuggs) = 0 THEN MSGBOX "The spelling seems to be correct" ELSE MSGBOX JOIN$(sSuggs(), $CRLF), 0, "How about one of these?" END IF END FUNCTION
Comment