Spellchecker and Grammar Checker

  • Thread starter Thread starter Bart
  • Start date Start date
B

Bart

I have created a form that allows my user to type in a
text box and run a spell-check and grammar check using
WORD. My problem is that it opens a word document after
running the spell-check and grammar check. I would really
like it to not open the word document at all but I have
been unsuccessful in getting it to programmatically close
the word document. I would appreciate any advice.

'The following code runs a spell check and grammar check

Private Sub cmdSpellCheck_Click()

Dim oWDBasic As Object
Dim sTmpString As String

Set oWDBasic = CreateObject("Word.Basic")
oWDBasic.FileNew
txtFreeForm.SetFocus
oWDBasic.Insert txtFreeForm.Text
On Error Resume Next
oWDBasic.ToolsSpelling
oWDBasic.ToolsGrammar
oWDBasic.EditSelectAll
oWDBasic.SetDocumentVar "MyVar", WDBasic.Selection
sTmpString = oWDBasic.GetDocumentVar("MyVar")
'The following code will NOT close WORD
'DoCmd.Close acModule, "word.basic", acSaveNo
'DoCmd.Close , "word.basic", acSaveNo
'DoCmd.Close , oWDBasic, acSaveNo
'oWDBasic.Quit
txtFreeForm.Text = Left(sTmpString,Len(sTmpString) - 1)
MsgBox "The spell check and grammar check are complete"

End Sub

Private Sub cmdOk_Click()

txtFreeForm.SetFocus
gstrFreeForm = txtFreeForm.Text
If IsNull(txtFreeForm) Then
MsgBox "You must type something in the text box"
Else
DoCmd.Close
End If

End Sub
 
I've never bothered with the Grammar checker, but here's the code I use to
invoke the Word Spell checker:

Function WordSpellCheckFull(WordToCheck As String) As Boolean
Dim wd As Word.Application
Dim wdsp As Word.SpellingSuggestions
Dim intLoop As Integer
Dim strPossible As String

On Error GoTo Err_WordSpellCheckFull

DoCmd.Hourglass True

If Len(WordToCheck) > 0 Then

Set wd = New Word.Application
If Not wd.CheckSpelling(WordToCheck) Then
wd.Documents.Add
Set wdsp = wd.GetSpellingSuggestions(WordToCheck)

If wdsp.Count > 0 Then
If wdsp.Count = 1 Then
strPossible = "Here is a possible word:" & vbCrLf &
vbCrLf
Else
strPossible = "Here are " & CStr(wdsp.Count) & "
possible words:" & vbCrLf & vbCrLf
End If

For intLoop = 1 To wdsp.Count
strPossible = strPossible & wdsp(intLoop).Name & vbCrLf
Next intLoop

wd.Documents.Close
Set wdsp = Nothing

Else

strPossible = "No suggestions"

End If

MsgBox strPossible
WordSpellCheckFull = False

Else

WordSpellCheckFull = True

End If
Else
MsgBox "You have to give me a word!"
End If

End_WordSpellCheckFull:
If Not wd Is Nothing Then
wd.Quit
Set wd = Nothing
End If
DoCmd.Hourglass False
Exit Function

Err_WordSpellCheckFull:
MsgBox Err.Description
Resume End_WordSpellCheckFull

End Function
 
Back
Top