-
I remember someone saying that it was possible to take the contents of a text box and run it through the MS word spell checker.
Am I remembering this correctly?
If so, do you know where it is located.
thank you for your time and have a good day
------------------
I am so skeptacle, I can hardly believe it!
-
Create a new Form with a TextBox, set it's
Multiline Property to True. Add a label
and two Command Buttons. Set the Label's Caption to "Type something in the Box to check it's spelling. Set Command1's Caption
to "Open Word's Spell Checker". Set the second Command Button's Caption to Exit. Set a Reference to MS Word Object Library(Project
Menu-References) and add the following code:
Code:
Option Explicit
Public Function SpellCheck(ByVal IncorrectText$) As String
Dim Word As Object, retText$
On Error Resume Next
' Create the Object and open Word
Set Word = CreateObject("Word.Basic")
' Change the active window to Word, and insert
' the text from Text1 into Word.
Word.AppShow
Word.FileNew
Word.Insert IncorrectText
' Runs the Speller Corrector
Word.ToolsSpelling
Word.EditSelectAll
' Trim the trailing character from the returned text.
retText = Word.Selection$()
SpellCheck = Left$(retText, Len(retText) - 1)
' Close the Document and return to Visual Basic.
Word.FileClose 2
Show
'Set the word object to nothing to liberate the
' occupied memory
Set Word = Nothing
End Function
Private Sub Command1_Click()
Text1 = SpellCheck(Text1)
End Sub
Private Sub Command2_Click()
Unload Me
End
End Sub
-
'Here's one to spellcheck a Richtextbox
'From a button on a toolbar
If Button.Key = "spelling" Then
If Len(Editor) = 0 Then Exit Sub
On Error GoTo SpellCheckErr
Dim oWord As Object
Set oWord = CreateObject("Word.Application")
'Save the RTF Box contents to a temp file
Editor.SaveFile "c:\my documents\tmpfile", rtfRTF
'Open the saved doc and spellcheck it
oWord.Documents.Open "c:\my documents\tmpfile", rtfRTF
oWord.ActiveDocument.SpellingChecked = False
oWord.Options.IgnoreUppercase = False
oWord.ActiveDocument.CheckSpelling
'Save the changes to the rtfText and close
oWord.ActiveDocument.Save
oWord.ActiveDocument.Close
oWord.Quit
'Load the changes back to the rtfText text box
Editor.LoadFile "c:\my documents\tmpfile", rtfRTF
Set oWord = Nothing
Screen.MousePointer = vbDefault
MsgBox "Spell Check is complete", vbInformation, "Spell Check"
Exit Sub
SpellCheckErr:
MsgBox Err.Description, vbCritical, "Spell Check"
Set oWord = Nothing
End If
-
I have a question about this working with a text box. I am not using a Rich Text Box. This is just a text box.
When I run the code johnpc posted, it works but the return text is not formated and there are extra charaters (they look like rectangles on the screen) Is there a way to have word return the text the way it is originally formated?
example:
EC means Electrical contractor
CC means Controls contractor
FC means Fire Alarm contractor
is returned as:
EC means Electrical contractor CC means Controls contractor FC means Fire Alarm contractor
with a square symbol inserted between the end of one line and the beginning of another
thank you for your time and have a good day
------------------
I am so skeptacle, I can hardly believe it!
-
A little tips:
If you want Word to work completely in background, delete "Word.AppShow" in johnpc
answer, or replace with "Word.AppShow 1"
I had trouble quitting Word, so I replaced "Word.Close 2" with "Word.Exit 2"
(That "2" is for Word not asking to save the file just created)
Hope this helps!
-
If you are using vb6 you can use something like:
Text1.Text = Replace(SpellCheck(Text1.Text), vbCr, vbCrLf)
-
this is a thought but can I get word to save a temp ASCII text file and then read the file? My theory is that the text is getting formatting characters from word and somehow the VbCrLf that I sent gets lost.
when word pops up the text is formated correctly in the word application.
thank you for your time and have a good day
------------------
I am so skeptacle, I can hardly believe it!
-
FranC
thank you again for all of your help it worked great!
johnpc
thank you for your help I would be lost without your help
Cas21
thanks for your input but I did not have a Rich Text Box.
[This message has been edited by badgers (edited 12-28-1999).]
-
thank you very much for the input I will try to make word run unseen.
-
Yes I had that problem, Word refused to quit.
Once I changed to Word.Exit all was OK.
It worked OK in a 486 with Word (Office) 97 and also in a P II with Office 2000. What version do you have? Did you try oWord.Exit? Or perhaps Word.FileExit?
Hope this helps...
-
you have a good point. when I run this there is a session of word still in the background. When I exit my program the word session is still there.
I tried the word.exit 2 stuff but it does not seem to help.
any ideas? is it possible for my program to cause another program to exit?
------------------
I am so skeptacle, I can hardly believe it!
-
are you using early or late binding?
I have changed to early binding and the intellisense is not being nice.
I have windows NT 4.0 with service pack 5
Word 97 with SR-2
thank you for your time and have a good day
------------------
I am so skeptacle, I can hardly believe it!