Hi, I'm working on a program which uses the word.application method to check spelling of a current textbox. A snippet of the code is below. Basically, it all works grand, except that WORD is loaded in memory and stays there, even after the application exits. This also causes problems on subsequent spell checks, as the previous words seem to be stuck in the Word app... is there any way of completely unloading the Word.Application (AppWord in the code below) after each spellcheck?
-+{John Vogel}+-
Code:
Private Sub btnSpellCheck_Click()
Dim DRange As Range
On Error Resume Next
Set AppWord = GetObject(, "Word.Application")
If AppWord Is Nothing Then
Set AppWord = CreateObject("Word.Application")
If AppWord Is Nothing Then
MsgBox "Could not start Word. Application will end"
End
Else
NewInstance = True
End If
Else
NewInstance = False
End If
On Error GoTo ErrorHandler
AppWord.Documents.Add
Set DRange = AppWord.ActiveDocument.Range
DRange.InsertAfter Text1.Text
Set SpellCollection = DRange.SpellingErrors
If SpellCollection.Count > 0 Then
FrmSug.List1.Clear
FrmSug.List2.Clear
For iWord = 1 To SpellCollection.Count
FrmSug!List1.AddItem SpellCollection.Item(iWord)
If FrmSug!List1.List(FrmSug!List1.NewIndex) = FrmSug!List1.List(FrmSug!List1.NewIndex + 1) Then
FrmSug!List1.RemoveItem FrmSug!List1.NewIndex
End If
Next
End If
FrmSug.Show vbModal
Exit Sub
ErrorHandler:
MsgBox "The following error occured during the document's spelling checker" & Err.Description
End Sub
-+{John Vogel}+-