?
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
Medium Priority
?
427 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 2000 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
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…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

830 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