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

Excel process still running after program completion.

I have a python script that is driving Excel and using the win32com
module. However, upon program completion there's still an Excel.exe
process running in the background that I must terminate through Task
Manager. Reading up on other threads indicate that maybe I still have
some Excel objects referenced within my code. Is this why the process
doesn't terminate?

The related (I hope) parts of my code is here.

x1App = Dispatch("Excel.Application")
Book1 = x1App.Workbooks.Open(ExcelLogPath+"\\outputLog-template.xls")
x1App.Visible = 1
for sheets in Book1.Worksheets:
if sheets.Name == file_name:
sheetExists = True
if sheetExists != True:
activeSheet =
Book1.Worksheets.Add(After=Book1.Worksheets(1))
activeSheet.Name = file_name
testNum[file_name] = 0
Book1.Worksheets(file_name).Select()
Book1.ActiveSheet.Cells(1+(testNum[file_name]*20),1).Value = "Original
File Name"
Book1.ActiveSheet.Cells(2+(testNum[file_name]*20),1).Value =
file_name
Book1.ActiveSheet.Pictures().Insert(output).Select ()
Book1.SaveAs(Filename=path)
x1App.ActiveWorkbook.Close(SaveChanges=0)
x1App.Quit()
del x1App
del Book1
del activeSheet

What am I missing?

Sep 11 '07 #1
3 4827
On Sep 11, 12:59 pm, "Hamilton, William " <wham...@entergy.comwrote:
From: Chris
I have a python script that is driving Excel and using the win32com
module. However, upon program completion there's still an Excel.exe
process running in the background that I must terminate through Task
Manager. Reading up on other threads indicate that maybe I still have
some Excel objects referenced within my code. Is this why the process
doesn't terminate?
The related (I hope) parts of my code is here.
x1App = Dispatch("Excel.Application")
Book1 = x1App.Workbooks.Open(ExcelLogPath+"\\outputLog-template.xls")
x1App.Visible = 1
for sheets in Book1.Worksheets:
if sheets.Name == file_name:
sheetExists = True
if sheetExists != True:
activeSheet =
Book1.Worksheets.Add(After=Book1.Worksheets(1))
activeSheet.Name = file_name
testNum[file_name] = 0
Book1.Worksheets(file_name).Select()
Book1.ActiveSheet.Cells(1+(testNum[file_name]*20),1).Value = "Original
File Name"
Book1.ActiveSheet.Cells(2+(testNum[file_name]*20),1).Value =
file_name
Book1.ActiveSheet.Pictures().Insert(output).Select ()
Book1.SaveAs(Filename=path)
x1App.ActiveWorkbook.Close(SaveChanges=0)
x1App.Quit()
del x1App
del Book1
del activeSheet
What am I missing?

In my Excel projects, I terminate it with:

xlBook.Close()
xlApp.Quit()

I haven't had a problem with Excel staying open after the program ends.

(On a tangent, I want to find the person who thought it was a good idea
to use the same symbol in a font for 1, l, and I and do some unpleasant
things.)

--
-Bill Hamilton
That doesn't really fix the problem as I'm pretty sure its identical
code for
x1App.ActiveWorkbook.Close(SaveChanges=0)

I think where my problem lies is within my for each loop where I
search to see if the worksheet with the name already exists
for sheets in Book1.Worksheets:
if sheets.Name == file_name:
sheetExists = True
Since I'm assuming that it creates objects for each of the sheets and
I don't delete them...

Sep 11 '07 #2
On Sep 11, 1:26 pm, Chris <chris.ole...@gmail.comwrote:
On Sep 11, 12:59 pm, "Hamilton, William " <wham...@entergy.comwrote:
From: Chris
I have a python script that is driving Excel and using the win32com
module. However, upon program completion there's still an Excel.exe
process running in the background that I must terminate through Task
Manager. Reading up on other threads indicate that maybe I still have
some Excel objects referenced within my code. Is this why the process
doesn't terminate?
The related (I hope) parts of my code is here.
x1App = Dispatch("Excel.Application")
Book1 = x1App.Workbooks.Open(ExcelLogPath+"\\outputLog-template.xls")
x1App.Visible = 1
for sheets in Book1.Worksheets:
if sheets.Name == file_name:
sheetExists = True
if sheetExists != True:
activeSheet =
Book1.Worksheets.Add(After=Book1.Worksheets(1))
activeSheet.Name = file_name
testNum[file_name] = 0
Book1.Worksheets(file_name).Select()
Book1.ActiveSheet.Cells(1+(testNum[file_name]*20),1).Value = "Original
File Name"
Book1.ActiveSheet.Cells(2+(testNum[file_name]*20),1).Value =
file_name
Book1.ActiveSheet.Pictures().Insert(output).Select ()
Book1.SaveAs(Filename=path)
x1App.ActiveWorkbook.Close(SaveChanges=0)
x1App.Quit()
del x1App
del Book1
del activeSheet
What am I missing?
In my Excel projects, I terminate it with:
xlBook.Close()
xlApp.Quit()
I haven't had a problem with Excel staying open after the program ends.
(On a tangent, I want to find the person who thought it was a good idea
to use the same symbol in a font for 1, l, and I and do some unpleasant
things.)
--
-Bill Hamilton

That doesn't really fix the problem as I'm pretty sure its identical
code for
x1App.ActiveWorkbook.Close(SaveChanges=0)

I think where my problem lies is within my for each loop where I
search to see if the worksheet with the name already exists
for sheets in Book1.Worksheets:
if sheets.Name == file_name:
sheetExists = True

Since I'm assuming that it creates objects for each of the sheets and
I don't delete them...
Which I'm right... I added this code and now there's no EXCEL.EXE
process after my script completes

for sheets in Book1.Worksheets:
if sheets.Name == file_name:
sheetExists = True
sheets = None
del sheets

Sep 11 '07 #3
On Sep 11, 8:29 pm, Chris <chris.ole...@gmail.comwrote:
On Sep 11, 1:26 pm, Chris <chris.ole...@gmail.comwrote:
On Sep 11, 12:59 pm, "Hamilton, William " <wham...@entergy.comwrote:
From: Chris
I have a python script that is driving Excel and using the win32com
module. However, upon program completion there's still an Excel.exe
process running in the background that I must terminate through Task
Manager. Reading up on other threads indicate that maybe I still have
some Excel objects referenced within my code. Is this why the process
doesn't terminate?
The related (I hope) parts of my code is here.
x1App = Dispatch("Excel.Application")
Book1 = x1App.Workbooks.Open(ExcelLogPath+"\\outputLog-template.xls")
x1App.Visible = 1
for sheets in Book1.Worksheets:
if sheets.Name == file_name:
sheetExists = True
if sheetExists != True:
activeSheet =
Book1.Worksheets.Add(After=Book1.Worksheets(1))
activeSheet.Name = file_name
testNum[file_name] = 0
Book1.Worksheets(file_name).Select()
Book1.ActiveSheet.Cells(1+(testNum[file_name]*20),1).Value = "Original
File Name"
Book1.ActiveSheet.Cells(2+(testNum[file_name]*20),1).Value =
file_name
Book1.ActiveSheet.Pictures().Insert(output).Select ()
Book1.SaveAs(Filename=path)
x1App.ActiveWorkbook.Close(SaveChanges=0)
x1App.Quit()
del x1App
del Book1
del activeSheet
What am I missing?
In my Excel projects, I terminate it with:
xlBook.Close()
xlApp.Quit()
I haven't had a problem with Excel staying open after the program ends.
(On a tangent, I want to find the person who thought it was a good idea
to use the same symbol in a font for 1, l, and I and do some unpleasant
things.)
--
-Bill Hamilton
That doesn't really fix the problem as I'm pretty sure its identical
code for
x1App.ActiveWorkbook.Close(SaveChanges=0)
I think where my problem lies is within my for each loop where I
search to see if the worksheet with the name already exists
for sheets in Book1.Worksheets:
if sheets.Name == file_name:
sheetExists = True
Since I'm assuming that it creates objects for each of the sheets and
I don't delete them...

Which I'm right... I added this code and now there's no EXCEL.EXE
process after my script completes

for sheets in Book1.Worksheets:
if sheets.Name == file_name:
sheetExists = True
sheets = None
del sheets
You just need to 'del sheets' once after the loop, no need to do it in
every iteration. After your original loop the 'sheets' variable still
pointed to the last sheet object, probably causing it not to be
properly cleaned up. This is the only thing that your change fixes,
but it is simpler (and more readable) to just do it once after the
loop.

(Please add SOLVED or FIXED to the subject when your issue has been
resolved, so that people like me don't read the whole thread only to
find that their help is no longer needed.)

- Tal

Sep 12 '07 #4

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

Similar topics

2
by: Sri | last post by:
I am writing an asp.net applicaition using VB coding. In a function, I am opening an excel file with the following code, Dim objExcel As Object Dim objWorkBook As Object objExcel =...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
4
by: Prince Kumar | last post by:
I joined a company recently and they have a java program which hangs (does nothing) after a while. This is no way consistent. It could succeed quite a few times and can fail a few other times....
4
by: Powerguy | last post by:
Hi all, I've spent countless hours trying to get this silly EXCEL process to close once I have used it. If anyone can help it would really REALLy be appreciated! Below is my code- Dim t As...
2
by: Powerguy | last post by:
Hi all, I am looking for a way to get the Process id (or a handle) of an EXCEL process created from within my code. For example when the following code is executed: Dim EXL As...
2
by: easoftware | last post by:
I would like to be able to use VB 2003 .NET to check if Excel is running, and if it is, then do something with the active workbook. I can see if Excel is running: Private Sub GetAllExcelApps()...
5
by: mabond | last post by:
Hi recently read a posting and reply about Excel processs still running after the Appliction.Quit was called. Thought I might be able to use the same...
13
by: chuckie_9497 | last post by:
hello all you gurus. I am struggling with releasing com objects. I have isolated the problem to the code below. Objects are released and the process ends until I use "int k = sheet.Count;" Then...
7
by: =?Utf-8?B?VGVycnkgSG9sbGFuZA==?= | last post by:
I have a vb.net app that opens an excel worksheet, reads data and then closes the sheet. Im noticing that the Excel process is still running after I have closed and disposed of my excel objects. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.