473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

excell in the process window

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

Nov 21 '05 #1
2 1168
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

Nov 21 '05 #2
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

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Savas Ates | last post by:
i cant delete data from excell which i use as a database with asp .. i encounter an error report about isam. how can i delete data from excell help meee!
12
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am...
2
by: alvis | last post by:
I need to write a windows service that will read a excell spreadsheet and either update a row in my sql db or insert the row. My question is how do i read excell spreadsheet row by row in VB dotnet
1
by: Mustafa | last post by:
I have an ASP script where i am generating the excell sheet dynamically i am passing some column header text which is long text so i want it to display it vertically in column (cell).In excell i...
2
by: Robert Halstead | last post by:
Hi guys, I have a asp.net web app and it's connecting to an excell 2003 document (in another folder) via OleDataAdapter. Everything works and all, it's just that when I shutdown IE and try to...
0
by: Delforce | last post by:
Hi all, My application allows you to create a new excel file and then double click it in the list view to start it in excell. If the excell file is an existing one then I can start it now...
2
by: glibo | last post by:
I am trying to change the tab name when i open a excell spread sheet on the run time in c#. I changed it in the code: Response.AddHeader("content-disposition","filename=" + sFileName + ".xls");...
2
by: Bram2008 | last post by:
How to use macro in excel? Can i get some code to record excell data to vb? O y, i have project in vb, and i write data in vb, then i transfer it to excell to build chart. This is my code : ...
1
Ali Rizwan
by: Ali Rizwan | last post by:
Hi all, I m creating a database. The data for database will fetched from an excell sheet. Now how can i read an excell sheet and update my database with that excell sheet. Or I want to show...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.