I have a VB.Net app that creates a Word.Application and Word.Document
object. It loads a Word document. However, in my cleanup code when the user
closes the window, I call the Quit method the Word.Application object and
set the objects to nothign. This works fine except if the user closes Word
before closing the window. If the do this I get an "The RPC server is
unvailable" exception. Here's some sample code ...
Dim wa As Word.Application
Dim wd As Word.Document
Private Sub btnOpenDocument_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOpenDocument.Click
wa = New Word.Application
wd = wa.Documents.Open("C:\Temp\MyTestDocument.doc")
wa.Visible = True
wd.Activate()
End Sub
Private Sub Form3_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
wa.Quit()
wd = Nothing
wa = Nothing
End Sub
I thought I could check to see if WA Is Nothing, but that didn't work. Any
ideas on what I need to check to see if the user closed Word before the
Form3_Closing event fires? Thanks.
John
Fredrik Wahlgren - 06 Jan 2005 17:49 GMT
> I have a VB.Net app that creates a Word.Application and Word.Document
> object. It loads a Word document. However, in my cleanup code when the user
[quoted text clipped - 26 lines]
>
> John
Maybe you can catch the "user closes Word " event and set a property when
this happens.
/ Fredrik