Spellchecking from Visual Basic
Wednesday, 13 September 2006
Here’s a quick way to run a spellcheck on any data stream from within your VB6 application:
Function SpellCheck(Stream As String) As String
On Error Resume Next
Dim W As Object
Set W = CreateObject("Word.Basic")
SpellCheck = Stream
With W
.AppMinimize
.FileNewDefault
.EditSelectAll
.EditCut
.Insert Stream
.StartOfDocument
.ToolsSpelling
.EditSelectAll
If Mid(.Selection, Len(.Selection), 1) = Chr(13) Then
.Selection = Mid(.Selection, 1, Len(.Selection) - 1)
End If
If Len(.Selection) > 1 Then
SpellCheck = .Selection
End If
.FileCloseAll 2
.AppClose
End With
Set W = Nothing
End Function
It will only work on those PC’s that have Microsoft Word already installed. You may want to modify the error handling logic to suit your taste. I’ve simply chosen to return the original text if the function encounters any serious errors with the spellcheck library.
|