boes Posted December 5, 2002 Posted December 5, 2002 In my application I need to print out some data using MSWord. There fore I have dimensioned a Word.application and a Word.document. Everything works fine, the only problem is that I don't seem to be able to end the Word application. It always keeps running on the background. Everytime I give a print commando a new Word.exe starts. When I then take a look in the Windows task manager several Word.exe are running. Can someone give me a hint on this? Quote
*Gurus* Derek Stone Posted December 5, 2002 *Gurus* Posted December 5, 2002 First things first. Have you called Application.Quit()? Quote Posting Guidelines
Guest MyNuS Posted December 6, 2002 Posted December 6, 2002 Have you tried using the showwindow api function: Imports System.Runtime.InteropServices Public Const SW_HIDE = 0 Public Const SW_MINIMIZE = 2 Public Const SW_MAXIMIZE = 3 Public Const SW_RESTORE = 1 Public Const SW_SHOW = 5 <DllImport("user32.dll")> Public Function _ ShowWindow(ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Boolean End Function <DllImport("user32.dll")> Public Function _ FindWindow(ByVal strClassName As String, ByVal strWindowName _ As String) As Integer End Function Sub CloseWord() Dim winHwnd as integer 'To find the "ClassName you need to use an api spy such as Matrix API winHwnd = Findwindow("ClassName", vbNullString) ShowWindow(winHwnd, SW_HIDE) Quote
Guest MyNuS Posted December 6, 2002 Posted December 6, 2002 Or you might try the sendmessge function instead if it doesnt work. Quote
*Gurus* Derek Stone Posted December 6, 2002 *Gurus* Posted December 6, 2002 Hiding a window does NOT close an application. All it does is remove the window's WS_VISIBLE style. You'd still be left with instances of Word running, which is needless to say, poor programming. Quote Posting Guidelines
Guest MyNuS Posted December 7, 2002 Posted December 7, 2002 Does sendmessage WM_CLOSE close the program, or will an instance still be running? Quote
*Gurus* Derek Stone Posted December 7, 2002 *Gurus* Posted December 7, 2002 It might or might not. The application can simply choose to ignore the message, or if you're dealing with an open document the application could display a message box requiring user response. But yes, in most cases the window will be closed, terminating the message pump and ending the application. Quote Posting Guidelines
boes Posted December 9, 2002 Author Posted December 9, 2002 Today I first tried : objWord.application.quit(). This gave the following error : Quit is ambiguous across the inherited interfaces Word_application and Word.ApplicationsEvents2_Event. After searching for some more time I changed : objWord As Word.Application into : objWord As Word.Application_class Then it was possible to use objword.application.quit() which solved my problem Quote
Recommended Posts