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
414 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

28 Experts available now in Live!

Get 1:1 Help Now