On Thu, 30 Jun 2005 03:56:01 -0700, Sri <Sr*@discussion s.microsoft.com > wrote:
¤ I am writing an asp.net applicaition using VB coding.
¤
¤ In a function, I am opening an excel file with the following code,
¤ Dim objExcel As Object
¤ Dim objWorkBook As Object
¤ objExcel = CreateObject("E xcel.Applicatio n")
¤ objWorkBook = objExcel.Workbo oks.Open(target filename)
¤ * targetfilename is a variable that stores the excel file name and path.
¤
¤ In the error handler,
¤
¤ I want to kill only the excel application created using previous line of
¤ code. There can be any other excel application running in the server that
¤ were not created by this application. How will I identify the process ID of
¤ this excel application through code and kill the process.
You could use the FindWindow API function call
(
http://msdn.microsoft.com/library/de...findwindow.asp)
Declare Function FindWindow Lib "user32" Alias "FindWindow A" (ByVal lpClassName As String, ByVal
lpWindowName As String) As Int32
Declare Function PostMessage Lib "user32" Alias "PostMessag eA" (ByVal hwnd As Int32, ByVal wMsg
As Int32, _
ByVal wParam As Int32, ByVal
lParam As Int32) As Int32
Public Function TerminateExcel( )
Dim ClassName As String
Dim WindowHandle As Int32
Dim ReturnVal As Int32
Const WM_QUIT = &H12
Do
ClassName = "XLMain"
WindowHandle = FindWindow(Clas sName, Nothing)
If WindowHandle Then
ReturnVal = PostMessage(Win dowHandle, WM_QUIT, 0, 0)
End If
Loop Until WindowHandle = 0
End Function
Paul
~~~~
Microsoft MVP (Visual Basic)