Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default simple excel process not killed

the follwoing procedure create a simple Excel object and try to close it, but
the Excel process still in memory


public sub createExcel
Dim excelApp As Excel.Application
excelApp = New Excel.Application
excelApp.Application.Quit() ' I tried excelApp.Quit() and did not work
excelApp = Nothing
End sub

how can I solve it?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default simple excel process not killed

Make it visible to see what's causing the trouble:

excelApp.visible = true

before you try to quit

Excel may be waiting for a click of a button from you.



zino wrote:

the follwoing procedure create a simple Excel object and try to close it, but
the Excel process still in memory

public sub createExcel
Dim excelApp As Excel.Application
excelApp = New Excel.Application
excelApp.Application.Quit() ' I tried excelApp.Quit() and did not work
excelApp = Nothing
End sub

how can I solve it?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default simple excel process not killed

Hello Zino,

Could you try running the following VB code and see if you still have Excel
in the
task manger even after you close the VB app?

Private Sub Command1_Click()
Dim XL As New Excel.Application

Dim oBooks As Excel.Workbooks
Set oBooks = XL.Workbooks

Dim oBook As Excel.Workbook
Set oBook = oBooks.Open("C:\temp\Anyold.xls")

oBook.Close False

Set oBook = Nothing
Set oBooks = Nothing
XL.Quit
Set XL = Nothing

End
End Sub

Make sure that you have killed all the instances of Excel from the task
manager
before running the above code.

Also, you may use the following Code to kill the process of Excel in the
task manager directly.

Public Sub EraseExcel()
Dim pTemp As System.Diagnostics.Process()
pTemp = System.Diagnostics.Process.GetProcesses()
Dim pTempProcess As System.Diagnostics.Process

For Each pTempProcess In pTemp
Dim sProcessName As String =
pTempProcess.ProcessName
Dim sProcessID As Int32 =
pTempProcess.Id
If StrComp("excel", sProcessName,
CompareMethod.Text) = 0 Then
Dim pProcessTemp As
System.Diagnostics.Process
pProcessTemp =
Process.GetProcessById(sProcessID)
pProcessTemp.Kill()
pProcessTemp.Close()
End If
Next

End Sub

Also, please make sure all the Anti-Virus software and other third-party
software have been closed.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default simple excel process not killed

I tried your: "Private Sub Command1_Click() .... .."
but still, Excel did not get released .... ...

it was released successfully when I called your: "Public Sub
EraseExcel() ... .. "

I'm afraid killing excel process through "System.Diagnostics.Process .. . ."
will lead to potential issue on the server where the application is going to
be hosted and where there is many other applications/processes running ...
....






"Wei Lu [MSFT]" wrote:

Hello Zino,

Could you try running the following VB code and see if you still have Excel
in the
task manger even after you close the VB app?

Private Sub Command1_Click()
Dim XL As New Excel.Application

Dim oBooks As Excel.Workbooks
Set oBooks = XL.Workbooks

Dim oBook As Excel.Workbook
Set oBook = oBooks.Open("C:\temp\Anyold.xls")

oBook.Close False

Set oBook = Nothing
Set oBooks = Nothing
XL.Quit
Set XL = Nothing

End
End Sub

Make sure that you have killed all the instances of Excel from the task
manager
before running the above code.

Also, you may use the following Code to kill the process of Excel in the
task manager directly.

Public Sub EraseExcel()
Dim pTemp As System.Diagnostics.Process()
pTemp = System.Diagnostics.Process.GetProcesses()
Dim pTempProcess As System.Diagnostics.Process

For Each pTempProcess In pTemp
Dim sProcessName As String =
pTempProcess.ProcessName
Dim sProcessID As Int32 =
pTempProcess.Id
If StrComp("excel", sProcessName,
CompareMethod.Text) = 0 Then
Dim pProcessTemp As
System.Diagnostics.Process
pProcessTemp =
Process.GetProcessById(sProcessID)
pProcessTemp.Kill()
pProcessTemp.Close()
End If
Next

End Sub

Also, please make sure all the Anti-Virus software and other third-party
software have been closed.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default simple excel process not killed

Hello Zino,

You are using the VB.NET, right?

Please refer this KB article to resolve the issue.

317109 Office application does not quit after automation from Visual Studio
..NET client
http://support.microsoft.com/default...b;EN-US;317109

When Visual Studio .NET calls a COM object from managed code, it
automatically creates a Runtime Callable Wrapper (RCW). The RCW marshals
calls between the .NET application and the COM object. The RCW keeps a
reference count on the COM object. Therefore, if all references have not
been released on the RCW, the COM object does not quit.

So you need to use the following code:

Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
Catch
Finally
o = Nothing
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim oApp As New Excel.Application()
Dim oBooks As Excel.Workbooks = oApp.Workbooks
Dim oBook As Excel.Workbook = oBooks.Add
Dim oSheet As Excel.Worksheet = oApp.ActiveSheet

NAR(oSheet)
oBook.Close(False)
NAR(oBook)
NAR(oBooks)
oApp.Quit()
NAR(oApp)

Debug.WriteLine("Sleeping...")
System.Threading.Thread.Sleep(5000)
Debug.WriteLine("End Excel")
End Sub


Hope this helps.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default simple excel process not killed

thank you for the help. That solved my problem

"Wei Lu [MSFT]" wrote:

Hello Zino,

You are using the VB.NET, right?

Please refer this KB article to resolve the issue.

317109 Office application does not quit after automation from Visual Studio
.NET client
http://support.microsoft.com/default...b;EN-US;317109

When Visual Studio .NET calls a COM object from managed code, it
automatically creates a Runtime Callable Wrapper (RCW). The RCW marshals
calls between the .NET application and the COM object. The RCW keeps a
reference count on the COM object. Therefore, if all references have not
been released on the RCW, the COM object does not quit.

So you need to use the following code:

Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
Catch
Finally
o = Nothing
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim oApp As New Excel.Application()
Dim oBooks As Excel.Workbooks = oApp.Workbooks
Dim oBook As Excel.Workbook = oBooks.Add
Dim oSheet As Excel.Worksheet = oApp.ActiveSheet

NAR(oSheet)
oBook.Close(False)
NAR(oBook)
NAR(oBooks)
oApp.Quit()
NAR(oApp)

Debug.WriteLine("Sleeping...")
System.Threading.Thread.Sleep(5000)
Debug.WriteLine("End Excel")
End Sub


Hope this helps.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default simple excel process not killed

My pleasure, Zino.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default simple excel process not killed

Wei,

What reference library do I have to bind with to have access to:
System.Diagnostics.Process() and Process.GetProcessById()


"Wei Lu [MSFT]" wrote:

Hello Zino,

Could you try running the following VB code and see if you still have Excel
in the
task manger even after you close the VB app?

Private Sub Command1_Click()
Dim XL As New Excel.Application

Dim oBooks As Excel.Workbooks
Set oBooks = XL.Workbooks

Dim oBook As Excel.Workbook
Set oBook = oBooks.Open("C:\temp\Anyold.xls")

oBook.Close False

Set oBook = Nothing
Set oBooks = Nothing
XL.Quit
Set XL = Nothing

End
End Sub

Make sure that you have killed all the instances of Excel from the task
manager
before running the above code.

Also, you may use the following Code to kill the process of Excel in the
task manager directly.

Public Sub EraseExcel()
Dim pTemp As System.Diagnostics.Process()
pTemp = System.Diagnostics.Process.GetProcesses()
Dim pTempProcess As System.Diagnostics.Process

For Each pTempProcess In pTemp
Dim sProcessName As String =
pTempProcess.ProcessName
Dim sProcessID As Int32 =
pTempProcess.Id
If StrComp("excel", sProcessName,
CompareMethod.Text) = 0 Then
Dim pProcessTemp As
System.Diagnostics.Process
pProcessTemp =
Process.GetProcessById(sProcessID)
pProcessTemp.Kill()
pProcessTemp.Close()
End If
Next

End Sub

Also, please make sure all the Anti-Virus software and other third-party
software have been closed.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
EXCEL.EXE is not killed Mircea Pleteriu Excel Programming 2 March 9th 05 10:25 AM
Excel Instance is not killed from clasic asp RameshMarimuthu Excel Programming 2 January 17th 05 10:19 PM
How to count process running time ( process not finished) miao jie Excel Programming 0 January 13th 05 09:23 AM
How to count process running time ( process not finished) miao jie Excel Programming 2 January 12th 05 06:01 AM
I've killed the copy process Ken McLennan[_3_] Excel Programming 4 November 6th 04 12:10 PM


All times are GMT +1. The time now is 05:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"