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
418 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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