Solved

i would like to be able to  use microsoft word to spell check the text in a rich text box on a form

Posted on 2011-03-17
4
415 Views
Last Modified: 2012-05-11
can anyone proved me with the code in VS 2008 to be able to spell check the text in a rich text box entered by a user?

0
Comment
Question by:john M
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
omegaomega earned 500 total points
ID: 35162643
Hello, JMadden,

If you are free to change the contents of the clipboard you could use something like the code in the attached snippet.  

If you want to preserve the clipboard (and also the formatting in the RichTextBox) then you would have to copy the text from the RichTextBox to the word document and compare the text after the spell check with that before, replacing any changed words in the RichTextBox.  That's a bit more work.

Cheers,
Randy

Dim wrdApp As New Word.Application
        Dim wrdDoc As Word.Document = wrdApp.Documents.Add
        If (RichTextBox1.SelectionLength = 0) Then RichTextBox1.SelectAll()
        RichTextBox1.Cut()
        wrdDoc.Content.Paste()
        wrdDoc.CheckSpelling()
        wrdDoc.Content.Select()
        wrdDoc.Content.Copy()
        RichTextBox1.Paste()
        wrdDoc.Close(SaveChanges:=False)
        wrdApp.Quit()

Open in new window

0
 
LVL 3

Author Comment

by:john M
ID: 35167074
what imports do you need to add to get word.application
i got blue lines for Word.Application , Word.Document  




 Dim wrdApp As New Word.Application
    Dim wrdDoc As Word.Document = wrdApp.Documents.Add
        If (   .SelectionLength = 0) Then RichTextBox1.SelectAll()
        RichTextBox1.Cut()
        wrdDoc.Content.Paste()
        wrdDoc.CheckSpelling()
        wrdDoc.Content.Select()
        wrdDoc.Content.Copy()
        RichTextBox1.Paste()
        wrdDoc.Close(SaveChanges:=False)
        wrdApp.Quit()
0
 
LVL 12

Expert Comment

by:omegaomega
ID: 35167549
Hi, JMadden,

I am back in the dark ages using Office 2k, so my references look like this:

    Microsoft Office 9.0 Object Library (v = 2.1.0.0)
    Microsoft Word 9.0 Object Library (v = 8.1.0.0)

If you add just the reference for the appropriate version of Word (using the COM tab of the "Add References" dialog), you should find that the corresponding Office reference will also be added.

Cheers,
Randy
0
 
LVL 3

Author Closing Comment

by:john M
ID: 35167757
great stuff
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question