Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I cannot close Excel 2016 after executing a xlwings function

when I execute a an Xlwings function I can save and close the workbook. But I cannot close Excel 2016 anymore. Is this a known issue? How can I fix this?

like image 803
user2910705 Avatar asked Dec 11 '16 17:12

user2910705


People also ask

What is the latest version of Xlwings?

27.0 and v0. 27.1 (Mar 8, 2022) Feature PRO This release adds support for xlwings Server to the Excel Desktop apps on both Windows and macOS. The new VBA function RunRemotePython is equivalent to runPython in the JavaScript modules of Google Sheets and Excel on the web, see xlwings Server (GH1841).

What can you do with Xlwings?

Xlwings makes automating Excel with Python easy and can be used for- generating an automatic report, creating Excel embedded functions, manipulating Excel or CSV databases etc.

How do I import Xlwings?

To make this run, just import the VBA module xlwings. bas in the VBA editor (Open the VBA editor with Alt-F11, then go to File > Import File... and import the xlwings. bas file. ). It can be found in the directory of your xlwings installation.


1 Answers

Here is how I got it to work:

import xlwings as xw
wbPath = [WorkbookPath]
wb = xw.Book(wbPath) 
app = xw.apps.active    
wb.save(wbPath)
#wb.close()

app.quit()

Note that I commented out the line wb.close(). You can skip this step and instead set the app = active Excel instance, save the workbook, and then quit the app.

like image 112
EliSquared Avatar answered Sep 24 '22 01:09

EliSquared