Reputation: 353
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
Reputation: 400
pip install xlwings
xlwings addin install
Tools > References > xlwings
addin inside VBA.
If you not turn on this addin - then RunPython
dosnt work.
Upvotes: 0
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
Reputation: 1093
xlwings addin install
(see: https://docs.xlwings.org/en/stable/installation.html#add-in )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.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