How To Enable QTP code to use Microsoft Word Spell Check

January 30, 2009

The following code shows a function for checking the number of spelling and grammar errors in a string. This function is also used to check the accuracy of a specific property in all the objects of a given application.

Function NumberOfSpellErrors(strText) 
Dim objMsWord 
Set objMsWord = CreateObject("Word.Application") 
objMsWord.WordBasic.Insert strText 
NumberOfSpellErrors = objMsWord.ActiveDocument.SpellingErrors.Count 
objMsWord.Documents.Close (False) 
objMsWord.Quit ' close the application 
Set objMsWord = Nothing' Clear object memory 
End Function 
The following function uses the Spell errors function to check a specific property .Of all the objects with a given description which are under a given parent

Sub CheckAllObjects(ParentObj, ObjDesc, PropName) 
Dim ObjCol, idx, PropValue, OldReportMode 
OldReportMode = Reporter.Filter 
Reporter.Filter = 2 ' Report only errors 
If (IsNull(ParentObj)) Then 
Set ObjCol = Desktop.ChildObjects(ObjDesc) 
Set ObjCol = ParentObj.ChildObjects(ObjDesc) 
End If 
For idx=0 to ObjCol.count-1 
PropValue = ObjCol.Item(idx).GetROProperty(PropName) 
RetVal = NumberOfSpellErrors(PropValue) ' The actual spell check result 
If (RetVal > 0) Then 
ReportText = "Object #" & idx+1 & ": The '" & PropName & "' Property has " & RetVal & " spell errors (" & PropValue & ")" 
Reporter.ReportEvent 1, "Spell Check", ReportText 
End If 
Reporter.Filter = OldReportMode 
End Sub

You Might Also Like


    this is my website i would like to link to yours?


  3. Nice one dude.....please carry on .....want some more on macro stuff

  4. On my work there is problem with corrupted word files and I advised them one tool-how to fix corrupted word document,it helped them,software had helped me too,it is free to the best of my memory,utility can easily perform these operations and fix recover doc from any damaged document in Microsoft Word format,open your damaged file and press Analyze for fix read only documents in Office,allows to avoid Word documents is unreadable fix,will recover only plain text, without any images, graphics and formatting,export the contents into another document in Microsoft Word format.

  5. Awesome project, Mel! Wow! I love your idea with new use of digi-images! Thank you for sharing tutorial, templates and your wonderful inspiration! more templates easy to download