473,387 Members | 1,903 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,387 software developers and data experts.

Q317109

Several messages to microsoft newsgroups have been posted regarding excel's
persistence until a program is shut down, but there seems to be no answer.

KB article Q317109
http://support.microsoft.com/default...b;en-us;317109 seems to not
work? This question seems to be unanswered for VB net.

I don't have vb net. Programming with Visual Basic 6, the same behaviour is
easily reproduced - excel in the running processes list that won't go away.

try this:

'---------------------------------------
Dim oXLApp As Excel.Application
Dim oXLWb As Excel.Workbook
Dim oXLWs As Excel.Worksheet

Set oXLApp = New Excel.Application
oXLApp.DisplayAlerts = False

Set oXLWb = oXLApp.Workbooks.Add
oXLWb.Worksheets.Worksheets(1).Name = "my sheet"

Set oXLWs = oXLWb.Worksheets("my sheet")

'-- insert some data to excel

oXLApp.Quit
'// the above statement optional whether to close the instance of excel,
leave it open, save it prior in VB, whatever.

Set oXLWs = Nothing
Set oXLWb = Nothing
Set oXLApp = Nothing

'------------------------------
The excel object will stay in the process list no matter what combination of
the above is entered until the calling program is shut down. KB Q317109 says
this is by design. ahhhhhhhhhhh.

Help please. I want to get rid of excel without my users shutting down the
program.
Nov 21 '05 #1
5 2127
Yeager,

Following is my "canned" answer to the won't quit issue.
In addition, the line of code...
oXLWb.Worksheets.Worksheets(1).Name = "my sheet"
should read...
oXLWb.Worksheets(1).Name = "my sheet"

'-------------------------------------------------------------
Here are some general guidelines to use when automating Excel...

1. Set a reference to the primary Excel objects used in your program.
Dim xlApp As Excel.Application
Dim WB As Excel.Workbook
Dim WS As Excel.Worksheet

Set xlApp = New Excel.Application
Set WB = xlApp.Workbooks.Add
Set WS = WB.Sheets(1)

Use the appropriate reference Every Time you make reference to a spreadsheet.
Do not use Range(xx) - use WS.Range(xx)
Cells should be WS.Cells(10, 20) or _
WS.Range(WS.Cells(10, 20, WS.Cells(20, 40))

2. Avoid the use of ActiveSheet, ActiveWorkbook, Selection etc.
Use your object references.

3. Avoid the use of the "With" construct.

4. Set all objects to Nothing in the proper order - child then parent.
Set WS = Nothing
WB.Close SaveChanges:=True 'your choice
Set WB = Nothing
xlApp.Quit
Set xlApp = Nothing

Violating any of these guidelines can leave "orphans" that still refer
to Excel and prevent the application from closing.
'-------------------------------------------------------------
Articles dealing with unqualified references and automation application not quitting:

1. 178510 - PRB: Excel Automation Fails Second Time Code Runs
http:// support.microsoft.com / default.aspx?scid=kb%3ben-us%3b178510
Summary: While running code that uses Automation to control Microsoft Excel,
one of the following errors may occur: With Microsoft Excel 97 and later, you receive the error:
Run-time error '1004': Method '<name of method>' of object '_Global' failed -or-...

2. 189618 - PRB: Automation Error Calling Unqualified Method or Property
http:// support.microsoft.com / default.aspx?scid=kb%3ben-us%3b189618
Summary: While running code that uses Automation to control Microsoft Word 97, Word 2000, or Word 2002,
you may receive one of the following error messages:
Run-time error '-2147023174' (800706ba) Automation error -or- Run-time error '462': The remote server...

3. 199219 - XL2000: Automation Doesn't Release Excel Object from Memory
http://support.microsoft.com/default...;en-us;q199219
When you run a macro that uses automation to create a Microsoft Excel object (instance),
the Excel object does not exit from memory when you specify.
If you create another Excel object after quitting the first, a second instance is in memory.
This problem occurs when your macro uses a "WITH" statement that refers to the automation object.

4. 319832 - INFO: Error or Unexpected Behavior with Office Automation When You Use Early Binding in Visual Basic
http:// support.microsoft.com / default.aspx?scid=kb%3ben-us%3b319832
Summary: When you automate a Microsoft Office application,
you may receive an error message or you may experience unexpected behavior, as follows.
You may receive one of the following error messages: Error 91: Object variable or With block variable not set....
'-------------------------------------------------------------

Regards,
Jim Cone
San Francisco, CA
"Yeager Simpson" <pl****@no.email> wrote in message news:uB**************@tk2msftngp13.phx.gbl...
Several messages to microsoft newsgroups have been posted regarding excel's
persistence until a program is shut down, but there seems to be no answer.
KB article Q317109
http://support.microsoft.com/default...b;en-us;317109 seems to not
work? This question seems to be unanswered for VB net.
I don't have vb net. Programming with Visual Basic 6, the same behaviour is
easily reproduced - excel in the running processes list that won't go away.
try this:
'---------------------------------------
Dim oXLApp As Excel.Application
Dim oXLWb As Excel.Workbook
Dim oXLWs As Excel.Worksheet
Set oXLApp = New Excel.Application
oXLApp.DisplayAlerts = False
Set oXLWb = oXLApp.Workbooks.Add
oXLWb.Worksheets.Worksheets(1).Name = "my sheet"
Set oXLWs = oXLWb.Worksheets("my sheet")
'-- insert some data to excel
oXLApp.Quit
'// the above statement optional whether to close the instance of excel,
leave it open, save it prior in VB, whatever.
Set oXLWs = Nothing
Set oXLWb = Nothing
Set oXLApp = Nothing
'------------------------------
The excel object will stay in the process list no matter what combination of
the above is entered until the calling program is shut down. KB Q317109 says
this is by design. ahhhhhhhhhhh.
Help please. I want to get rid of excel without my users shutting down the
program.


Nov 21 '05 #2
Hi Yeager
Use
System.Runtime.InteropServices.Marshal.ReleaseComO bject
(xlApp) that will close excel if there are more
references to it. You also use the process class to kill
the process.

Kind Regards
Jorge
-----Original Message-----
Several messages to microsoft newsgroups have been posted regarding excel'spersistence until a program is shut down, but there seems to be no answer.
KB article Q317109
http://support.microsoft.com/default.aspx?scid=kb;en- us;317109 seems to notwork? This question seems to be unanswered for VB net.

I don't have vb net. Programming with Visual Basic 6, the same behaviour iseasily reproduced - excel in the running processes list that won't go away.
try this:

'---------------------------------------
Dim oXLApp As Excel.Application
Dim oXLWb As Excel.Workbook
Dim oXLWs As Excel.Worksheet

Set oXLApp = New Excel.Application
oXLApp.DisplayAlerts = False

Set oXLWb = oXLApp.Workbooks.Add
oXLWb.Worksheets.Worksheets(1).Name = "my sheet"

Set oXLWs = oXLWb.Worksheets("my sheet")

'-- insert some data to excel

oXLApp.Quit
'// the above statement optional whether to close the instance of excel,leave it open, save it prior in VB, whatever.

Set oXLWs = Nothing
Set oXLWb = Nothing
Set oXLApp = Nothing

'------------------------------
The excel object will stay in the process list no matter what combination ofthe above is entered until the calling program is shut down. KB Q317109 saysthis is by design. ahhhhhhhhhhh.

Help please. I want to get rid of excel without my users shutting down theprogram.
.

Nov 21 '05 #3
Jim

Your note has been extremely helpful.

Before I read this I had been searching for a while to resolve the
persistence of EXCEL.EXE process.

Thanks very much.

Naveen

Nov 21 '05 #4
I have been working on making excel go away, only in VC++, using the example
code I found in KB articles 186120, 186122, and 179706.

So far I have narrowed it down to using the Open method of the Workbooks
object.
If I start Excel, add a workbook, put some information in it, save the
workbook and call the Quit method on the application object, Excel disappears
from the system's task list, just like its supposed to.

If I start Excel, get a reference to the workbooks object, though
GetWorkbooks, and open a workbook, (with no other action taking place) Excel
disappears from view, but won't exit the systems task list.

Next approach is grabbing a snapshot of the processes in the system, before
and after Excel is starting, then killing off the new copy of Excel when I
need Excel to exit. Not pretty, but have no other ideas at present...

There is a lot of extra potential for my application if I can solve this,
any help is appreciated.

David
"Naveen" wrote:
Jim

Your note has been extremely helpful.

Before I read this I had been searching for a while to resolve the
persistence of EXCEL.EXE process.

Thanks very much.

Naveen

Nov 21 '05 #5
Hi,

This works for me. I hope it helps you.

Private Function closeExcel() As Short
Dim count As Short = 0
Dim excelInstance As System.Diagnostics.Process
Dim excelInstances() As Process =
System.Diagnostics.Process.GetProcessesByName("Exc el")
For Each excelInstance In excelInstances
Try
excelInstance.Close() '<-- you can use close or kill .. up to you
excelInstance.Kill()
count += 1
Catch ex As Exception
End Try
Next
Return count
End Function

http://www.kjmsolutions.com/datasetarray.htm

"DGT3" <DG**@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com:
I have been working on making excel go away, only in VC++, using the
example
code I found in KB articles 186120, 186122, and 179706.

So far I have narrowed it down to using the Open method of the Workbooks

object.
If I start Excel, add a workbook, put some information in it, save the
workbook and call the Quit method on the application object, Excel
disappears
from the system's task list, just like its supposed to.

If I start Excel, get a reference to the workbooks object, though
GetWorkbooks, and open a workbook, (with no other action taking place)
Excel
disappears from view, but won't exit the systems task list.

Next approach is grabbing a snapshot of the processes in the system,
before
and after Excel is starting, then killing off the new copy of Excel when I

need Excel to exit. Not pretty, but have no other ideas at present...

There is a lot of extra potential for my application if I can solve this,

any help is appreciated.

David
"Naveen" wrote:
Jim

Your note has been extremely helpful.

Before I read this I had been searching for a while to resolve the
persistence of EXCEL.EXE process.

Thanks very much.

Naveen


Nov 21 '05 #6

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

Similar topics

3
by: Maciej Pietruszka | last post by:
My app read from Excel file using Excel's COM dll I create Excel object by: Excel.Application ExcelObj = new Excel.Application(); and next make it inivisible: ExcelObj.Visible = false; ...
11
by: Antonio | last post by:
Hello, here is what I am doing. 1) user accesses web page and clicks button to build report 2) web page accesses web service whose data type is DataSet (public DataSet methodname()...) 3) web...
8
by: ChrisBowringGG | last post by:
When you use Application.Quit() on an Excel application, there can still be an instance of Excel running, as seen in Task Manager. You can try following the advice on MSDN: ...
3
by: Max | last post by:
I use late binding to have my program compatible with multiple versions of Microsoft Outlook. Here is a snipped of my code that launches Microsoft Outlook and displays it to the user: Type...
0
by: tsansoterra | last post by:
I have an asp.net/vb.net app that opens Excel, creates a report and then saves the file for download. The problem I am having is the Excel process persists (visible under the Task Manager) after...
5
by: al | last post by:
Greetings, I used article Q317109 (http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q317109) to solve the problem of Excel prcocess does not stop after close. The problem I faced with...
4
by: Dries | last post by:
Hello, I am using Excel Interop to export data from a dataset to an excel-file. Everything works fine except closing the excel-file. I have an Application-object and a Workbook-object. I call...
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...
2
by: ChrisFrohlich | last post by:
I have been trying to use the Office PIA's to write an ASP.NEt page to: 1. Open a template workbook 2. Populate some data 3. Save the file back to the server 4. Quit Excel and free up Memory I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.