[python-win32] Best Way to 'Dispose' of COM / Excel

Mark Hammond mhammond@skippinet.com.au
Thu, 6 Jun 2002 08:47:15 +1000


> here's what i'm using now:
> =============================================
> ExcelApp=win32com.client.dynamic.Dispatch("Excel.Application")
> ExcelApp.Visible = 0
> workbook = ExcelApp.Workbooks.Add()
> ...
> workbook.SaveAs(Filename=thePath + "\\" + strExcelFileName + ".xls")
> workbook.Close(0)
> ExcelApp.Quit()
> ExcelApp = None
> =============================================
>
> thanks much in advance!

That should be fine.  However, just before terminating you should check that
pythoncom._GetInterfaceCount() returns zero.  If non-zero, it means that
there is still a reference to a COM object somewhere in your program, and it
should be removed.

Mark.