472,964 Members | 2,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,964 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 4760
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. ...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.