Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spell/Grammar Checking

Status
Not open for further replies.

Skie

Programmer
Jun 21, 2004
475
US
What I'd like to do is say take text (either typed into the program or from a text file) and run it through a spelling and grammar check.

The spell checking part isn't too hard. I just have a list of words and say does this word = oneofthese words. If so, it's all gravy baby. But, I don't even want to touch coding for grammar checking.

What'd be cool is if I could tap into Word's spelling and grammar check. Have those dialogboxes pop up without the user ever seein Word. Is this doable?

Here's my flow:
Get Text
Load Word
Paste Text into Word
Run Spelling/Grammar Check - Don't know how, but I imagine it wouldn't take more than a quick search.
Display Dialog Boxes w/o Showing Word - I need help here.
Grab Modified Text From Word
Return Modified Text to User

Any help with this is greatly appreciated.
 
Nevermind, found what I was looking for on the net. Posted the code incase someone is looking for something similar.

Code:
' Grammar and Spell-Checker for clipboard contents.  Requires MS Word
' Steve Yandl, May 8, 2001
' This is an upgrade to Spell.vbs that checked spelling only.
' /////////////////////////////////////////////////////////////////
'
Dim oWD, RangeOriginal, RangeCorrected, Cnt, Status
Set oWD = WScript.CreateObject("Word.Application")
oWD.Visible =false
oWD.Documents.Add
On Error Resume Next
oWD.Selection.Paste
If err.number<>0 then
MsgBox "Clipboard was Empty"
oWD.ActiveDocument.Close wdDoNotSaveChanges
oWD.Quit
Set oWD=Nothing
Set oWD=Nothing
WScript.Quit
End If
'
Set RangeOriginal=oWD.ActiveDocument.Range(0,oWD.Selection.End)
oWD.ActiveDocument.Options.CheckGrammarWithSpelling = True
If oWD.CheckGrammar(RangeOriginal)=False Then
oWD.ActiveDocument.CheckGrammar
Set RangeCorrected = oWD.ActiveDocument.Range(0,oWD.Selection.End)
RangeCorrected.copy
'
If RangeCorrected.Words.Count>7 Then
Cnt=RangeCorrected.Words.Count
Status= "The text beginning with: "&_
RangeCorrected.Words.Item(1)&" "&RangeCorrected.Words.Item(2)&" "&_
RangeCorrected.Words.Item(3)&"....."&vbCRLF&"and ending with: ....."&_
RangeCorrected.Words.Item(Cnt-2)&" "&RangeCorrected.Words.Item(Cnt-1)&_
" "&RangeCorrected.Words.Item(Cnt)&vbCRLF&"has been checked "&_
"and corrected version copied to the clipboard"
Else
Status= "<< "&RangeCorrected&" >>"&vbCRLF&"has been checked and the"&_
" corrected version was copied to the clipboard"
End If
'
Else
Status= "Any words in the clipboard were all spelled correctly"
End If
'
oWD.ActiveDocument.Close wdDoNotSaveChanges
oWD.Quit
Set oWD=Nothing
MsgBox Status
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top