devxlogo

Using MS Word to Spell-Check in PowerBuilder

Using MS Word to Spell-Check in PowerBuilder

Question:
I need to incorporate Microsoft Word 97 spell-check functionality into PowerBuilder. Which MS Word functions are required to do the task?

Answer:
To interface to the Word spelling checker you will need to use OLE Automation to create a link to the Word application, then call the correct Word Basic functions.

The following code opens up the spelling checker dialog box for you. Note that you will need to convert any CR/LFs in PowerBuilder to CRs before calling the Word dialog box and then change the CRs back to CR/LFs after calling the module.

 OleObject lole_SpellLong ll_RCSetPointer( HourGlass! )// Word is available so replace all CR/LFs with CRsthis.ReplaceChar( as_Text, '~r~n', '~r' )// Connect to Word and do a spell-checklole_Spell = CREATE OleObjectll_RC = lole_Spell.ConnectToNewObject( 'Word.Application' )IF ll_RC <> 0 THEN	DESTROY lole_Spell	RETURN ll_RCEND IFlole_Spell.Application.Visible = Falselole_Spell.Application.WindowState = 2lole_Spell.Documents.Add()lole_Spell.Selection.TypeText( as_Text )lole_Spell.Selection.HomeKey()lole_Spell.Selection.MoveStart()lole_Spell.ActiveDocument.CheckSpelling()lole_Spell.ActiveDocument.Select()as_Text = lole_Spell.Selection.Textlole_Spell.ActiveDocument.Close( False )lole_Spell.Application.Quitlole_Spell.DisconnectObject()DESTROY lole_Spell// Change the CRs back to CR/LFsthis.ReplaceChar( as_Text, '~r', '~r~n' )

as_Text will now contain text with the correct spelling.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist