|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Waiting for com program to terminateI 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 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: Show quoteHide quote > 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 > > Hello again, Bob,
I've just seen your later post, and (if your staring Word as a process rather than as an application) Cor's answer there is much better . That is: Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles Button1.Click Dim procWord As Process = Process.Start("Mydoc.doc") MsgBox("Waiting for Word to close...") procWord.WaitForExit() MsgBox("Continuing...") End Sub Cheers, Randy R. MacDonald wrote: Show quoteHide quote > 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 >>
Populating date into SQL
How to mask console password input How to query the table in a dataset? VB.NET and Microsoft Word problem: topic becomes read-only Launching Word 2003 in prog creates exception IE input box from TreeView Compiling list of items that WinForms can do, WebForms cannot Creating Reports from SQL data Filename from Open With how to format text for email message |
|||||||||||||||||||||||