Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

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)

Posted
Or you might try the sendmessge function instead if it doesnt work.
Posted
Does sendmessage WM_CLOSE close the program, or will an instance still be running?
  • *Gurus*
Posted
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.
Posted

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...