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!

Getting rid of the word.application after using it for a search 1

Status
Not open for further replies.

JohnVogel

Programmer
Apr 19, 1999
117
US
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?

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}+-


 
Try:

wordapp.Quit (wdDoNotSaveChanges) ' or wdPromptToSaveChanges/wdSaveChanges
Set wordapp = Nothing

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Thank you John... that was easy enough.. Now all I have to figure out is why it STILL keeps the old spellcheck in my listboxes. Well, if I can't figure it out, I know where to turn ;)

Thanks again!

-+{John Vogel}+-


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top