Connecting Tech Pros Worldwide Forums | Help | Site Map

Closing an excel application

Newbie
 
Join Date: Sep 2007
Location: Buffalo, NY
Posts: 25
#1: Jul 8 '09
Hi All....

I'm using python 2.4, Win XP Pro v.2002 sp3, and I use pyscripter 1.9.9.2 as my editor.

I have written code to open an existing excel file and grab some data. The problem I am having is closing down the excel application. Here some "bits" of the code I am using:

Expand|Select|Wrap|Line Numbers
  1. xlApp = Dispatch("Excel.Application")
  2.  
  3. xlApp.Workbooks.Open(Filename = path+fname)
I am closing the workbook by doing the following:

Expand|Select|Wrap|Line Numbers
  1. xlApp.Workbooks.Close()
I am trying to quit the excel application by doing the following:

Expand|Select|Wrap|Line Numbers
  1. xlApp.quit()
The problem is when I check the windows Task Manager, the EXCEL.EXE is still present. From all I have read, this is the correct way to close the workbook and exit the excel application.

Can anyone tell me what I might be doing wrong.

Thanks in advance.

Silgd1

Newbie
 
Join Date: Sep 2007
Location: Buffalo, NY
Posts: 25
#2: Jul 9 '09

re: Closing an excel application


I found out that you must do the following:

Expand|Select|Wrap|Line Numbers
  1. xlApp.Visible = 0
  2. del xlApp
you must make x1App.Visible=0 before you use del x1App, otherwise EXCEL.EXE remains in memory.
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,638
#3: Jul 10 '09

re: Closing an excel application


Thanks for updating us with the solution. I am only somewhat familiar with win32com. I usually interface with Excel using CSV files.

-BV
Reply