在VB中(不是VBA)怎样才能检测到窗口关闭?该如何处理

在VB中(不是VBA)怎样才能检测到窗口关闭??
我想这里word高手比较多,所以在这里问问

Dim   wdApp   As   New   Word.Application

With   wdApp
        .Visible   =   True
        .Documents.Add   App.Path   &   "\doc\plan.dot ",   False,   wdNewBlankDocument,   True
        .ActiveDocument.Variables( "PLANNAME ")   =   "教育1 "
        .ActiveDocument.Variables( "cdate ")   =   Date
        .ActiveDocument.Content.Select
        .ActiveDocument.Content.Fields.Update

' '   stop   program...
do   while   .documents.count=0
      doevents
loop
End   With

然后我想让程序等待,直到word窗口关闭为止继续,可是我用
.documents.count=0
可以测出文档关闭,但是一但word窗口关闭,.documents.count语句就报错,说是什么远程服务器不存在,怎么才能测到word窗口关闭呢??

------解决方案--------------------
加一名no Error Resume Next

do while .documents.count=0 or err.Number

建议,DoEvnets之后加一名 API:Sleep
------解决方案--------------------
那就判断.documents.count之前先判断word的进程是否存在,你出错主要是因为引用的对象word已经妖折了.

或者你新建一个word.doument 并将它.visable=false,这样在理论上word.applictaion不会被直接销毁.