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
413 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
great stuff
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now