Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
Spell Check a Textbox
View previous topic :: View next topic  
Author Message
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Oct 8th, 2003 06:03 AM    Post subject: Spell Check a Textbox Reply with quote

Add this code to a command button or popup menu item.

Code:
Dim objWord As Object
    Dim objDoc  As Object
    Dim strResult As String
   
    'Create a new instance of word Application
    Set objWord = CreateObject("word.Application")

    Select Case objWord.Version
        'Office 2000
        Case "9.0"
            Set objDoc = objWord.Documents.Add(, , 1, True)
        'Office XP
        Case "10.0"
            Set objDoc = objWord.Documents.Add(, , 1, True)
        'Office 97
        Case Else ' Office 97
            Set objDoc = objWord.Documents.Add
    End Select

    objDoc.Content = Text1.Text
    objDoc.CheckSpelling

    strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)

    If Text1.Text = strResult Then
        ' There were no spelling errors, so give the user a
        ' visual signal that something happened
        MsgBox "The spelling check is complete.", vbInformation + vbOKOnly
    End If
   
    'Clean up
    objDoc.Close False
    Set objDoc = Nothing
    objWord.Application.Quit True
    Set objWord = Nothing

    ' Replace the selected text with the corrected text. It's important that
    ' this be done after the "Clean Up" because otherwise there are problems
    ' with the screen not repainting
    Text1.Text = strResult

    Exit Sub
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic