Hello, Bob,
This isn't "elegant", but seems to work:
Imports System.Threading.Thread
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
. . .
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim appWord As New Word.Application
appWord.Visible = True
MsgBox("Waiting for Word to close...")
Do
Try
' Examine some (any) property of Word application.
Dim booTest As Boolean = appWord.Visible
Sleep(100)
Catch ex As COMException
If (ex.ErrorCode = &H80010108) Then
' object has disconnected from its clients.
MsgBox("Continuing...")
Exit Do
Else
' Unexpected error.
Throw New Exception(ex.Message, ex)
End If
Catch ex As Exception
' Unexpected error.
Throw New Exception(ex.Message, ex)
End Try
Loop
End Sub
End Class
Cheers,
Randy
Bob wrote:
I launch Word from within my application (Vs2005, VB) and I would like to
make it necessary for the just opened Word to be closed before the rest of
my code in the calling sub can execute. How can I do this?
Thanks for any help
Bob