I’m trying to use the xlwings add-in to run Python modules from excel. I’m starting with this basic Python script, named xlwings_test.py:
import numpy as np
import xlwings as xw
def main():
wb = xw.Book.caller()
ws = wb.sheets[0]
ws['A1'].value = 'Hello'
This is based on the xlwings quickstart tutorial. I then created an excel file called xlwings_test.xlsm, made sure it was in the same folder as the Python code (which was also the folder that PYTHONPATH points to in the xlwings ribbon), then hit the “Run main” button in the xlwings ribbon. When I do, I get a Visual Basic error.
The same happens if I try to run it from VBA with this code:
Sub xlwings_test()
RunPython "import xlwings_test; xlwings_test.main()"
End Sub
I’ve reinstalled the xlwings add-on from scratch and that didn’t solve the problem. I also made sure that xlwings is enabled within VBA -> Tools -> References. What exactly could be giving this error?
3