473,403 Members | 2,284 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,403 software developers and data experts.

Can't close EXCEL from my VB.NET application

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
Mar 31 '06 #1
7 16188
Hi,

Use marshal.releasecomobject

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

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

"SteveS" wrote:
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

Mar 31 '06 #2
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:
Hi,

Use marshal.releasecomobject

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

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

"SteveS" wrote:
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

Mar 31 '06 #3
"SteveS" <St****@discussions.microsoft.com> schrieb:
I used the following but it still leaves a Excel process open in Task
Manager.


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/>

Apr 1 '06 #4
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" <St****@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
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:
Hi,

Use marshal.releasecomobject

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

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

"SteveS" wrote:
> 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

Apr 1 '06 #5
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:
"SteveS" <St****@discussions.microsoft.com> schrieb:
I used the following but it still leaves a Excel process open in Task
Manager.


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/>

Apr 3 '06 #6
"SteveS" <St****@discussions.microsoft.com> schrieb:
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)


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/>

Apr 3 '06 #7
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

Apr 5 '06 #8

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

Similar topics

1
by: Andrei Ryazanov | last post by:
Hello, All! i try the following text from mvps.org Sub sTestXL() Dim objXL As Object Dim strWhat As String, boolXL As Boolean Dim objActiveWkb As Object If fIsAppRunning("Excel") Then Set...
0
by: Stewart Allen | last post by:
Hi there, I've got some code to open up an Excel workbook but what I want is for the code to pause until the Excel workbook is closed. Sub EditWorkbook(strFile as String) Dim xlApp As...
2
by: Ronny Sigo | last post by:
Hello all, I have to open a readonly Excel sheet from clicking on a button on an access form. So far no problem: Dim ObjXL As Excel.Application Dim ObjXLBook As Excel.Workbook Dim ObjXLSheet As...
0
by: I Decker | last post by:
Hi all, Hope this is the right group. I am writing a program in c# to open create an excel document, enter some data, save it and then email it as an attachment. I have successfully created...
6
by: Daniel | last post by:
Hi all, Can i open and edit the excel sheet on web page after downloading? After editing, i close the web page and the excel file auto upload to the server. Is it possible? I really struggling...
16
by: LP | last post by:
Hello, I am trying to use .NET with Excel. I installed Office 2003 and selected ..NET programming suport option, so it installed all those PIA, as MS sugests. But I can not find a way to destroy...
8
by: SteveS | last post by:
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...
4
by: Abdhul Saleem | last post by:
Hi, I am recieving error ActiveX component can't create object in the following line in the asp page. set ExcelApp = CreateObject("Excel.Application") Previously this code was working fine....
2
by: iloveprincess | last post by:
Hi, I'm developing windows application using VB.Net 2005. I would like to send 'save' message using 'SendMessage' API to the excel appication. I've already got a handle of the excel window with...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.