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 >
CodePudding user response:
The only way I figured it out was to import xlwings as follows:
import xlwings as xw
then at end, I placed in the code: book = xw.Book() book.app.quit()
CodePudding user response:
instead of writing wb.close, use
wb.Close(True)
this should close the file