This little test seemed to work, start a new Standard EXE, cut and paste the following code, set a Reference the the Word Library, and press F5. It should open up ten documents and then displays the count in a msgbox in the VBIDE. Just close the form, upon exiting it will try to kill each individual document and then will continue setting the word app object var to nothing until it is actually nothing.
Code:Option Explicit Dim wdApp As Word.Application Dim intCount As Integer Private Sub Form_Load() Set wdApp = New Word.Application For intCount = 1 To 10 wdApp.Documents.Add Next wdApp.Visible = True MsgBox wdApp.Documents.Count End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Dim objDoc As Word.Document On Error Resume Next If Not wdApp Is Nothing Then For Each objDoc In wdApp.Documents objDoc.Close False Next End If wdApp.Quit Do Until wdApp Is Nothing Debug.Print "Die Word Die!" Set wdApp = Nothing Loop End Sub




Reply With Quote