CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Help!

  1. #1
    Join Date
    May 2001
    Posts
    155

    Help!

    how do you spell check a rich text box?


  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Help!

    you can use a third party component or automate MS word. here's a sample:

    private Function FN_SpellCheck(strTextToVerify as string) as Boolean
    on error GoTo FN_SpellCheckErr

    Dim oWord as Word.Application
    Dim oDoc as Word.Document
    Dim strSelection as string

    set oWord = GetObject(, "Word.Application")

    oWord.WindowState = wdWindowStateMinimize

    set oDoc = oWord.Documents.Add

    oDoc.Content.Select

    ' done immediately before to minimize possibility of user
    ' interaction with the clipboard

    Clipboard.SetText strTextToVerify, vbCFRTF

    oDoc.Range.Paste

    oDoc.GoTo Which:=wdGoToFirst, what:=wdGoToLine

    on error resume next
    oDoc.CheckSpelling IgnoreUppercase:=true, AlwaysSuggest:=false

    on error GoTo 0
    oDoc.Content.Select

    oDoc.Range.Copy

    strSelection = Clipboard.GetText(vbCFRTF)

    If mid(strSelection, len(strSelection), 1) = Chr(13) then
    strSelection = mid(strSelection, 1, len(strSelection) - 1)
    End If

    If len(strSelection) > 1 then
    strTextToVerify = strSelection
    FN_SpellCheck = true
    End If

    oDoc.Close wdDoNotSaveChanges

    set oDoc = nothing
    set oWord = nothing

    Exit Function

    FN_SpellCheckErr:
    MsgBox error

    End Function




    you can call it like this:

    If FN_SpellCheck(Text1.Text) then
    MsgBox "No errors"
    else
    MsgBox "Errors in document."
    End If




    hope that helps,

    john

    John Pirkey
    MCSD
    http://www.ShallowWaterSystems.com
    http://www.stlvbug.org
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured