Close Excel file along with the excel application it opened

Viewed 32

I have the following python code that opens my excel file and closes it; however, the Excel app remains open. I have other python script running in the background so I only want to close the application it opened when it opened the file (not all running Excel applications).

xlapp = win32com.client.DispatchEx("Excel.Application")
xlapp.DisplayAlerts = False
xlapp.Visible = True
wb = xlapp.Workbooks.Open(file_path)


if refresh1 == True:
    wb.RefreshAll()
    xlapp.CalculateUntilAsyncQueriesDone()

wb.Save
wb.SaveAs(yestmoPath, FileFormat="51")
wb.close

I tried xlapp.quit at the end and receive this message: <bound method quit of >

1 Answers

The only way I figured it out was to import xlwings as follows:

import xlwings as xw

then at the end, I placed the code:

book = xw.Book()
book.app.quit()
Related