Or, instead of using loops, why not use an event-based solution? Put the
below code in an Excel code module, call Initialize() and Terminate() as
appropriate, and you'll be able to listen to Application Quit and Document
Close events through the event handlers. I would strongly recommend the use
of event-based programming whereever and whenever possible, instead of
implementing tight loops to poll for state information, since the latter will
consume CPU cycles for virtually no good reason.
Cheers,
/MP
====================================
Option Explicit
Private WithEvents g_oApp As Word.Application
Private WithEvents g_oDoc As Word.Document
Private Sub Initialize()
Set g_oApp = CreateObject("Word.Application")
Set g_oDoc = g_oApp.Documents.Add
g_oApp.Visible = True
End Sub
Private Sub Terminate()
Set g_oDoc = Nothing
Set g_oApp = Nothing
End Sub
Private Sub g_oApp_Quit()
MsgBox "Word App Quit"
End Sub
Private Sub g_oDoc_Close()
MsgBox "Word Doc Close"
End Sub
==============================================
"Tom Ogilvy" wrote:
Without testing
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.documents.Add
Set objDoc = Nothing
do while objWord.Visible
loop
set objWord = Nothing
Msgbox ("Excel again")
--
Regards,
Tom Ogilvy
"H.A. de Wilde" wrote:
Dear Tom,
thank you for your reply.
Unfortunately I am not able to check for the existence of Word.
Which condition should I use to exit the loop?
With kind regards,
Hugo
--
H.A. de Wilde
------------------------------------------------------------------------
H.A. de Wilde's Profile: http://www.excelforum.com/member.php...o&userid=30679
View this thread: http://www.excelforum.com/showthread...hreadid=538800