How to Quit Excel with win32com, without saving?

Viewed 3612

When I do xl.Quit(), Excel always pops up with a prompt that ask whether or not I want to save. How do tell it I don't want to save?

xl = Dispatch('Excel.Application')
xl.Workbooks.Open('New Workbook.xlsx')
# do some stuff

xl.Quit()
1 Answers
from win32com.client import Dispatch

# Start excel application
xl = Dispatch('Excel.Application')

# Open existing excel file
book = xl.Workbooks.Open('workbook.xlsx')

# Some arbitrary excel operations ...    

# Close excel application without saving file
book.Close(SaveChanges=False)
xl.Quit()
Related