Connecting Tech Pros Worldwide Forums | Help | Site Map

Can't close EXCEL from my VB.NET application

SteveS
Guest
 
Posts: n/a
#1: Mar 31 '06
I'm attempting to close EXCEL from within my VB.NET application.
Using the excel object library to write data to my spreadsheet is working
fine but when I try to quit application object it does not work. I know this
because I can still see the Excel application running in Task Manager.

How do I shut down EXCEL?

I have tried the QUIT method and Interop.RemoveComponent.

--
Thank You

Ken Tucker [MVP]
Guest
 
Posts: n/a
#2: Mar 31 '06

re: Can't close EXCEL from my VB.NET application


Hi,

Use marshal.releasecomobject

http://www.vb-tips.com/default.aspx?...3-cc46c8615787

Ken
---------------

"SteveS" wrote:
[color=blue]
> I'm attempting to close EXCEL from within my VB.NET application.
> Using the excel object library to write data to my spreadsheet is working
> fine but when I try to quit application object it does not work. I know this
> because I can still see the Excel application running in Task Manager.
>
> How do I shut down EXCEL?
>
> I have tried the QUIT method and Interop.RemoveComponent.
>
> --
> Thank You[/color]
SteveS
Guest
 
Posts: n/a
#3: Mar 31 '06

re: Can't close EXCEL from my VB.NET application


Ken,
I used the following but it still leaves a Excel process open in Task
Manager.

System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlApp)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wb)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlSheet)
xlApp = Nothing
wb = Nothing
xlSheet = Nothing

GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()

--
Thank You


"Ken Tucker [MVP]" wrote:
[color=blue]
> Hi,
>
> Use marshal.releasecomobject
>
> http://www.vb-tips.com/default.aspx?...3-cc46c8615787
>
> Ken
> ---------------
>
> "SteveS" wrote:
>[color=green]
> > I'm attempting to close EXCEL from within my VB.NET application.
> > Using the excel object library to write data to my spreadsheet is working
> > fine but when I try to quit application object it does not work. I know this
> > because I can still see the Excel application running in Task Manager.
> >
> > How do I shut down EXCEL?
> >
> > I have tried the QUIT method and Interop.RemoveComponent.
> >
> > --
> > Thank You[/color][/color]
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#4: Apr 1 '06

re: Can't close EXCEL from my VB.NET application


"SteveS" <SteveS@discussions.microsoft.com> schrieb:[color=blue]
> I used the following but it still leaves a Excel process open in Task
> Manager.[/color]

Make sure you are releasing the objects in the order they were created. In
addition you may want to post relevant parts of the code to enable people
here to determine whether or not you are really releasing all objects.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jim Hughes
Guest
 
Posts: n/a
#5: Apr 1 '06

re: Can't close EXCEL from my VB.NET application


This works for me:

'Clean-up: Close the workbook and quit Excel.
If oBook IsNot Nothing Then
oBook.Close(False)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(oBook)
oBook = Nothing
End If
If oBooks IsNot Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(oBooks)
oBooks = Nothing
End If
If oExcel IsNot Nothing Then
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(oExcel)
oExcel = Nothing
End If

"SteveS" <SteveS@discussions.microsoft.com> wrote in message
news:1F8ADD54-0BEA-4862-8643-288900B3C5FD@microsoft.com...[color=blue]
> Ken,
> I used the following but it still leaves a Excel process open in Task
> Manager.
>
> System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlApp)
> System.Runtime.InteropServices.Marshal.ReleaseComO bject(wb)
> System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlSheet)
> xlApp = Nothing
> wb = Nothing
> xlSheet = Nothing
>
> GC.Collect()
> GC.WaitForPendingFinalizers()
> GC.Collect()
>
> --
> Thank You
>
>
> "Ken Tucker [MVP]" wrote:
>[color=green]
>> Hi,
>>
>> Use marshal.releasecomobject
>>
>> http://www.vb-tips.com/default.aspx?...3-cc46c8615787
>>
>> Ken
>> ---------------
>>
>> "SteveS" wrote:
>>[color=darkred]
>> > I'm attempting to close EXCEL from within my VB.NET application.
>> > Using the excel object library to write data to my spreadsheet is
>> > working
>> > fine but when I try to quit application object it does not work. I
>> > know this
>> > because I can still see the Excel application running in Task Manager.
>> >
>> > How do I shut down EXCEL?
>> >
>> > I have tried the QUIT method and Interop.RemoveComponent.
>> >
>> > --
>> > Thank You[/color][/color][/color]


SteveS
Guest
 
Posts: n/a
#6: Apr 3 '06

re: Can't close EXCEL from my VB.NET application


I've tried your resolution and other posts offering diiferent resolutions
unfortunately the EXCEL process remains present in Task Manager.
I've attached my code in hopes that it may shed some light on the issue.
As you can see the code is quite simple.....

My code is shown below:

Dim xlapp As Excel.Application
xlapp = CType(CreateObject("Excel.Application"), Excel.Application)
Dim wb As Excel.Workbook = xlapp.Workbooks.Open(fileName)
Dim xlSheet As Excel.Worksheet

Dim currRow As Integer

xlSheet = wb.Worksheets(1)
currRow = PTLRecordNumber

xlSheet.Cells(currRow, 1) = Me.LotNumber
xlSheet.Cells(currRow, 2) = Me.ScrewMachineNumber
xlSheet.Cells(currRow, 3) = Me.PartNumber
xlSheet.Cells(currRow, 4) = Me.PlatingDate
xlSheet.Cells(currRow, 5) = 0
xlSheet.Cells(currRow, 6) = Me.LoadSize
xlSheet.Cells(currRow, 7) = Me.FullLoad
xlSheet.Cells(currRow, 8) = Me.Mean
xlSheet.Cells(currRow, 9) = Me.Hi
xlSheet.Cells(currRow, 10) = Me.Low
xlSheet.Cells(currRow, 11) = Me.PLTankNumber
xlSheet.Cells(currRow, 12) = Me.BasketNumber
xlSheet.Cells(currRow, 13) = Me.CarrierNumber
xlSheet.Cells(currRow, 14) = Me.AdhesionTest
xlSheet.Cells(currRow, 15) = Me.SolderabilityTest
xlSheet.Cells(currRow, 16) = Me.OscilineNiTank
xlSheet.Cells(currRow, 17) = Me.Comments

'ss wb.SaveAs(fileName, Excel.XlFileFormat.xlExcel9795)
wb.Save()
wb.Close()
xlapp.Quit()
'ss xlApp.UserControl = True
'ss xlApp.Visible = True

'Attempt to close excel - notorious problem with .net not closing
all instances of Excel in task manager!!
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlSheet)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wb)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlapp)
xlapp = Nothing
wb = Nothing
xlSheet = Nothing

GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()


--
Thank You


"Herfried K. Wagner [MVP]" wrote:
[color=blue]
> "SteveS" <SteveS@discussions.microsoft.com> schrieb:[color=green]
> > I used the following but it still leaves a Excel process open in Task
> > Manager.[/color]
>
> Make sure you are releasing the objects in the order they were created. In
> addition you may want to post relevant parts of the code to enable people
> here to determine whether or not you are really releasing all objects.
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://classicvb.org/petition/>
>
>[/color]
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#7: Apr 3 '06

re: Can't close EXCEL from my VB.NET application


"SteveS" <SteveS@discussions.microsoft.com> schrieb:[color=blue]
> I've tried your resolution and other posts offering diiferent resolutions
> unfortunately the EXCEL process remains present in Task Manager.
> I've attached my code in hopes that it may shed some light on the issue.
> As you can see the code is quite simple.....
>
> My code is shown below:
>
> Dim xlapp As Excel.Application
> xlapp = CType(CreateObject("Excel.Application"), Excel.Application)[/color]

Why not use 'New Excel.Application()'? Additionally I suggest to wait a few
seconds after your application has released the references. Excel is an
automation server that typically doesn't shut down immediately after the
last reference has been removed.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

aaron.kempf@gmail.com
Guest
 
Posts: n/a
#8: Apr 5 '06

re: Can't close EXCEL from my VB.NET application


excel is a piece of crap you should remove excel from every computer on
your network

the biggest time-waster ever invented; at least i know it's worse than
even internet explorer lol

learn Accesss or SQL screw excel in the mouth

Closed Thread