Skip to content
Advertisement

python win32 COM closing excel workbook

I open several different workbooks (excel xlsx format) in COM, and mess with them. As the program progresses I wish to close one specific workbook but keep the rest open.

How do I close ONE workbook? (instead of the entire excel application)

JavaScript

Advertisement

Answer

The the Workbook COM object has a Close() method. Basically, it should be something like:

JavaScript

The above was just a skeleton here’s some code that works on my machine against Office 2010:

JavaScript

Of course, that creates a new xlsx file. But then I’m able to successfully open and modify the file in the same session as follows:

JavaScript

Don’t know if any of that helps…

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement