Can't close Excel completely using win32com on Python Can't close Excel completely using win32com on Python python python

Can't close Excel completely using win32com on Python


Try this:

wbs.Close()excel.Quit()del excel # this line removed it from task manager in my case


I have this in my files that use Excel:

self.excel.Application.Quit()


What worked for me was making sure to de-reference any variables that you assigned along the way like so:

import win32com.client as win32fileDirectory = 'Hello World.xlsx'#excelFile = win32.Dispatch('Excel.Application')excelFile = win32.gencache.EnsureDispatch('Excel.Application')excelFile.Visible = TrueexcelFile.DisplayAlerts = Truewb = excelFile.Workbooks.Open(fileDirectory)ws = wb.Sheets("Sell")ws.Range("D1").Value = "Hello World!"ws = Nonewb.Close(False)wb = NoneexcelFile.Quit()excelFile = None

It worked with either Dispatch format.