Ending Word.exe

boes

Member
Joined
Jun 21, 2002
Messages
17
Location
Belgium
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 dont 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?
 
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)
 
Hiding a window does NOT close an application. All it does is remove the windows WS_VISIBLE style. Youd still be left with instances of Word running, which is needless to say, poor programming.
 
Does sendmessage WM_CLOSE close the program, or will an instance still be running?
 
It might or might not. The application can simply choose to ignore the message, or if youre 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.
 
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
 
Back
Top