VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



OLE Automation Start a new project in Visual Basic. Form1 is created as the default form. Add a tex

by Zvenny (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 26th October 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

OLE Automation Start a new project in Visual Basic. Form1 is created as the default form. Add a text box (Text1) and command button (Command1)

Rate OLE Automation Start a new project in Visual Basic. Form1 is created as the default form. Add a tex




   Sub Form_Load()

'center form
Me.Move (Screen.Width - Me.Width)/2, (Screen.Height - Me.Height)/2
'set text to be checked in text box
txtOle.Text = "Ole automation is graet. The posibilities ar endless!" 

   End Sub

Place the following code in the cmdSpell_Click event procedure of Form1: 

Sub cmdSpell_Click ()
Dim WordObj As Object
Dim sTmp As String

      Set WordObj = CreateObject("Word.Basic")

      'start new file
      WordObj.FileNew

      'clear selection
      WordObj.EditClear

      If txtOle.SelText <> "" Then
        'insert only selected text in VB Text Box
        WordObj.Insert txtOle.SelText
      Else
        'insert all text from VB text box
        WordObj.Insert txtOle.Text
      End If

      'perform error handling
      On Error GoTo OleError

      'position to begining of document
      WordObj.StartOfDocument

      'position to end of document, selecting all text in between
      WordObj.EndOfDocument (1)

      'invoke Word spell checker
      WordObj.ToolsSpelling

      'select corrected text and copy into buffer
      WordObj.EditSelectAll
      WordObj.SetDocumentVar "MyVar", WordObj.Selection
      sTmp = WordObj.GetDocumentVar("MyVar")

      'replace contents of text box with corrected text
      txtOle.Text = Left(sTmp, Len(sTmp) - 1)
      
      MsgBox "The Spell Check is complete"

      Exit Sub

OleError:

      'resume at next line
      Resume Next
End Sub

Hit F5 to run the program.
Click the SpellCheck button, and go through the following sequence of corrections:

   Ole (Ignore)
   graet(Change to great)
   posibilities(Change to possibilities)
   ar(Change to are)

After the last correction, you will get a Message box telling you that the Spell Check is complete. The results inserted back into the text box should say this: 
  "Ole automation is great. The possibilities are endless!" 



Download this snippet    Add to My Saved Code

OLE Automation Start a new project in Visual Basic. Form1 is created as the default form. Add a tex Comments

No comments have been posted about OLE Automation Start a new project in Visual Basic. Form1 is created as the default form. Add a tex. Why not be the first to post a comment about OLE Automation Start a new project in Visual Basic. Form1 is created as the default form. Add a tex.

Post your comment

Subject:
Message:
0/1000 characters