Simplify your business
Tuesday, 7 October 2008 1:00 pm

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.


Got something to say?

To protect your privacy, your email address will not be displayed.





Some basic rules for commenting:

  • Watch your language.
  • Keep comments on-topic and relevant.
  • You can use basic XHTML tags for formatting and linking but not bbcode.
  • Comments are moderated, so don't double post if your comment doesn't appear immediately.
  • Please proof-read your comments for spelling and grammar mistakes.
  • Watch your language.