|
-
Dec 23rd, 1999, 04:14 AM
#1
Thread Starter
Hyperactive Member
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!
-
Dec 23rd, 1999, 04:53 AM
#2
Addicted Member
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
-
Dec 23rd, 1999, 09:44 AM
#3
Lively Member
'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
-
Dec 27th, 1999, 11:54 PM
#4
Thread Starter
Hyperactive Member
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!
-
Dec 28th, 1999, 08:54 AM
#5
Hyperactive Member
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!
-
Dec 28th, 1999, 12:10 PM
#6
If you are using vb6 you can use something like:
Text1.Text = Replace(SpellCheck(Text1.Text), vbCr, vbCrLf)
-
Dec 28th, 1999, 12:14 PM
#7
Thread Starter
Hyperactive Member
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!
-
Dec 28th, 1999, 12:31 PM
#8
Thread Starter
Hyperactive Member
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).]
-
Dec 28th, 1999, 09:58 PM
#9
Thread Starter
Hyperactive Member
thank you very much for the input I will try to make word run unseen.
-
Dec 29th, 1999, 08:05 AM
#10
Hyperactive Member
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...
-
Dec 29th, 1999, 12:30 PM
#11
Thread Starter
Hyperactive Member
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!
-
Dec 29th, 1999, 10:11 PM
#12
Thread Starter
Hyperactive Member
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|