473,789 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.RemoveC omponent.

--
Thank You
Mar 31 '06 #1
7 16235
Hi,

Use marshal.release comobject

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.RemoveC omponent.

--
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.Releas eComObject(xlAp p)
System.Runtime. InteropServices .Marshal.Releas eComObject(wb)
System.Runtime. InteropServices .Marshal.Releas eComObject(xlSh eet)
xlApp = Nothing
wb = Nothing
xlSheet = Nothing

GC.Collect()
GC.WaitForPendi ngFinalizers()
GC.Collect()

--
Thank You
"Ken Tucker [MVP]" wrote:
Hi,

Use marshal.release comobject

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.RemoveC omponent.

--
Thank You

Mar 31 '06 #3
"SteveS" <St****@discuss ions.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(Fal se)
System.Runtime. InteropServices .Marshal.Releas eComObject(oBoo k)
oBook = Nothing
End If
If oBooks IsNot Nothing Then
System.Runtime. InteropServices .Marshal.Releas eComObject(oBoo ks)
oBooks = Nothing
End If
If oExcel IsNot Nothing Then
oExcel.Quit()
System.Runtime. InteropServices .Marshal.Releas eComObject(oExc el)
oExcel = Nothing
End If

"SteveS" <St****@discuss ions.microsoft. com> wrote in message
news:1F******** *************** ***********@mic rosoft.com...
Ken,
I used the following but it still leaves a Excel process open in Task
Manager.

System.Runtime. InteropServices .Marshal.Releas eComObject(xlAp p)
System.Runtime. InteropServices .Marshal.Releas eComObject(wb)
System.Runtime. InteropServices .Marshal.Releas eComObject(xlSh eet)
xlApp = Nothing
wb = Nothing
xlSheet = Nothing

GC.Collect()
GC.WaitForPendi ngFinalizers()
GC.Collect()

--
Thank You
"Ken Tucker [MVP]" wrote:
Hi,

Use marshal.release comobject

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.RemoveC omponent.
>
> --
> 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.Applicati on
xlapp = CType(CreateObj ect("Excel.Appl ication"), Excel.Applicati on)
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(c urrRow, 1) = Me.LotNumber
xlSheet.Cells(c urrRow, 2) = Me.ScrewMachine Number
xlSheet.Cells(c urrRow, 3) = Me.PartNumber
xlSheet.Cells(c urrRow, 4) = Me.PlatingDate
xlSheet.Cells(c urrRow, 5) = 0
xlSheet.Cells(c urrRow, 6) = Me.LoadSize
xlSheet.Cells(c urrRow, 7) = Me.FullLoad
xlSheet.Cells(c urrRow, 8) = Me.Mean
xlSheet.Cells(c urrRow, 9) = Me.Hi
xlSheet.Cells(c urrRow, 10) = Me.Low
xlSheet.Cells(c urrRow, 11) = Me.PLTankNumber
xlSheet.Cells(c urrRow, 12) = Me.BasketNumber
xlSheet.Cells(c urrRow, 13) = Me.CarrierNumbe r
xlSheet.Cells(c urrRow, 14) = Me.AdhesionTest
xlSheet.Cells(c urrRow, 15) = Me.Solderabilit yTest
xlSheet.Cells(c urrRow, 16) = Me.OscilineNiTa nk
xlSheet.Cells(c urrRow, 17) = Me.Comments

'ss wb.SaveAs(fileN ame, Excel.XlFileFor mat.xlExcel9795 )
wb.Save()
wb.Close()
xlapp.Quit()
'ss xlApp.UserContr ol = 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.Releas eComObject(xlSh eet)
System.Runtime. InteropServices .Marshal.Releas eComObject(wb)
System.Runtime. InteropServices .Marshal.Releas eComObject(xlap p)
xlapp = Nothing
wb = Nothing
xlSheet = Nothing

GC.Collect()
GC.WaitForPendi ngFinalizers()
GC.Collect()
GC.WaitForPendi ngFinalizers()
GC.Collect()
--
Thank You
"Herfried K. Wagner [MVP]" wrote:
"SteveS" <St****@discuss ions.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****@discuss ions.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.Applicati on
xlapp = CType(CreateObj ect("Excel.Appl ication"), Excel.Applicati on)


Why not use 'New Excel.Applicati on()'? 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
14980
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 objXL = GetObject(, "Excel.Application")
0
1369
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 Excel.Application Dim xlWorkBook As Excel.Workbook Dim strPath As String
2
651
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 Excel.Worksheet Set ObjXL = CreateObject("Excel.Application") Set ObjXLBook = ObjXL.Workbooks.Open("Mypath\Myfile.xls", , True) Set ObjXLSheet = ObjXLBook.Worksheets("Main") ObjXL.Visible = True
0
41184
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 an excel document which the user can see (at this stage of development) and passed some data to it. I then used the savas method to save the file. Again this seems to work as the file is created. However once I close the excel file and try and...
6
6768
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 about the ability. If not, what advice can u provide? thank you in advance. ur help will be appreaciated.
16
4553
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 Excel process, it still hangs in the taks manager' Processes as running. I am trying very simple code (see below), but Excel wont go away, I tried just about anything I could find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But...
8
38170
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 work. I know this because I can still see the Excel application running in Task Manager. How do I shut down EXCEL? -- Thank You
4
11338
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. Thanks in advance.
2
2809
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 'FindWindow' API. How can I send 'save' command to external excel window? Actual thing I want to do is I can handle excel application in the winform. My client hope that all staff can use excel application in new window
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10412
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7529
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3703
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.