Private Function IsExcelRunning() As Boolean
Dim pExcel As System.Diagnostics.Process() =
System.Diagnostics.Process.GetProcessesByName("exc el")
If pExcel.Length >= 1 Then
Return True
Else
Return False
End If
End Function
The above function will tell you if MS Excel is running
-----------------------------------------------------------------------
You could also check if Excel is running by:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Integer
Dim intExcel As Integer = FindWindow("xlmain", vbNullString)
If intExcel isn't 0 (zero) then Excel is running
------------------------------------------------------------------------------------------
To do the same thing along the lines as you, do this:
Imports System.Diagnostics
Dim p As Process
Dim proc As New Process
For Each p In Process.GetProcesses
If p.ProcessName = "EXCEL" Then
p.Kill()
End If
Next
"alvis" wrote:
hi i have a windows service that uses an excell workbook
when i create the excell app
i cant distroy it after i am finished i am using this code
whats wrong?
thanks
Dim processes1(), p1 As Process
Try
processes1 = Process.GetProcesses()
For Each p1 In processes1
If Not (p1.MainModule Is Nothing) Then
If
System.IO.Path.GetFileName(p1.MainModule.FileName) .ToLower() = "excel.exe"
Then
Try
p1.Close()
'p1.CloseMainWindow()
Catch er1 As Exception
MsgBox(er1)
End Try
'Exit For
End If
End If
Next
Catch ex As SystemException
MsgBox(ex.message)
End Try