user3763074
user3763074

Reputation: 353

Python Xlwings Not Running

Trying to launch a simple python hello world script that populates a cell in an Excel sheet using XLwings.

Was hoping to accomplish this simple task before using this approach to run something more elaborate. Unfortunately even this simple tasks seems to not be working. When I run the script off of a button push in Excel, the Excel file just says 'Running...' and nothing happens.

This also happens if I download and attempt to run the test files from XLwings.

I've looked at multiple posts here including here and here, as well as the docs and Youtube to attempt this.

Here's the python script:

import xlwings as xw

def SayHello():
    wb = xw.Book.caller()
    wb.sheets['test'].range("A1").value = "Hello World"

And here's the Excel VBA code:

Sub Call_Python_Function()
RunPython ("import hello; hello.SayHello()")
End Sub

I've added the XLwings.xlam file to the working directory, also enabled macros and the developer tab, ensured that XLwings was included in Excel Add-Ins, and enabled the xlwings.conf tab following the instructions on that sheet... and still nothing happens.

I'm a complete Excel n00b. Is there maybe something I missed in the set up for Excel? Have literally never run a macro before so wondering if there is something else I should be doing?

Upvotes: 1

Views: 5133

Answers (3)

Dmitry Dronov
Dmitry Dronov

Reputation: 400

  1. pip install xlwings
  2. xlwings addin install
  3. Check that you turn on Tools > References > xlwings addin inside VBA. If you not turn on this addin - then RunPython dosnt work. enter image description here

enter image description here

Upvotes: 0

infowizard
infowizard

Reputation: 1

I encountered the same issue. For me it was the version of xlwings installed in conda environment. The force upgrade was done with conda install -c conda-forge xlwings. After that I reinstalled the excel addin with xlwings addin install command. Python code runs as intended thereafter.

Upvotes: 0

cadvena
cadvena

Reputation: 1093

  1. Install the xlwings (xlwings.xlam) add-in to Excel with the shell command xlwings addin install (see: https://docs.xlwings.org/en/stable/installation.html#add-in )
  2. Run xlwings quickstart myproject or xlwings quickstart myproject --standalone to create your workbook (https://docs.xlwings.org/en/stable/addin.html?highlight=standalone). Consider using a fully qualified path for myproject.
  3. Confirm the add-in is installed as a reference in Excel (unless you use the xlwings quickstart --standalone command). To do this, open Excel's VBA Editor (Alt+F11) > Tools > Refernce... > [Browse...].
  4. You will find a working hello world procedure in Module1 within your new workbook. Make sure this works before trying your own code.

If these steps do not address your concern. Respond with how you are kicking off the procedure and the exact error you receive. Also, don't be afraid to run it using the Excel debugger (https://www.tutorialspoint.com/excel_macros/excel_macros_debugging_code.htm).

Upvotes: 0

Related Questions