1

I have an Excel file which relies heavily on UDFs programmed in python (xlwings). It works just great on a PC where python is installed along with the add-in. The problem is I have to send the file to a bunch of people who don't even know what python is. Because of UDFs, a frozen executable is out of the question. So what I did:

  1. Downloaded an embeddable python installation (Windows x86 embeddable zip file) from python.org, extracted it to the folder where the xlsm file is (in a separate folder named 'Python').

  2. Downloaded get-pip.py from bootstrap.pypa.io, uncommented the line 'import site' in the file python36._pth, ran 'python get.pip.py'.

  3. Downloaded pywin32 and comtypes wheels from Christoph Gohlke's great site, installed them with 'pip install [filename].whl'. Installed xlwings ('pip install xlwings'). The total size of this installation is 50Mb.

  4. Created a new file with a xlwings module installed ('xlwings quickstart myproject --standalone'). Renamed the '_xlwings.conf' sheet to 'xlwings.conf', entered the following formula in the 'Interpreter' field: =LEFT(CELL("filename";A1);FIND("[";CELL("filename";A1))-1) & "Python\pythonw.exe" It automatically calculates the correct path to the python interpreter wherever the file is opened.

Macros and UDFs seem to be working, but each time when I open the file all UDF formulas throw an 'ActiveX component can't create object' error. If I force a recalculation ([CTRL]-[ALT]-[SHIFT]-F9) everything starts working again, but I can't expect that my end users will know how to do this. Is there a trick to make UDFs work out of the box? Or maybe there's a more convenient way to distribute xlwings-powered Excel files?

4
  • If you replace the formula under point 4 with a hardcoded path for testing, do you see the same behaviour? Commented Oct 30, 2017 at 16:29
  • Sorry, forgot to mention that, of course I tried it, still got the same ActiveX error. Commented Oct 30, 2017 at 17:11
  • I'm not very familiar with xlwings, but have you tried running recalculation under the Workbook_Open event in ThisWorkbook? Commented Nov 6, 2017 at 22:31
  • Yes that did the trick. Thanks! Added the following VBA code, now it automatically runs a full recalculation as soon as the workbook is opened: Private Sub Workbook_Open() Application.CalculateFull End Sub Still feels like a workaround, but most importantly it gets the job done Commented Nov 7, 2017 at 19:10

1 Answer 1

0

As Phillip suggested in the comment section, the solid workaround is to add the following VBA code to the 'ThisWorkbook' module:

Private Sub Workbook_Open()
Application.CalculateFull
End Sub

It launches a full recalculation as soon as the workbook is opened. Still, it would be great if xlwings worked smoothly without any tinkering. Such a great package, in my opinion, the only thing that stops it from more widespread adoption is problems with distribution.

Unfortunately, I can't upvote Phillip's comment, can't thank him enough.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.