Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xlwings : Object Required

I'm a newbie into both python and xlwings. So the story is,

I need a custom function needs to be used in Excel. Since I have no clue about VB scripts, I decided to write a function in python and import it in excel using xlwings.

  • I installed xlwings using the pip command. I added the addin to excel by the procedure given in xlwings support forum.

  • I created an excel file, say " Test.xlsm". I created a python file in the same name "Test.py" (File is in same folder only)

I wrote my function in the python

import xlwings as xl
@xl.func
def exponent(x,y):
#the function is an example only. I tried this for practicing and it is also not working
    z=x**y
    return z
  • I opened excel, imported the functions using import function in xlwings addin. I found no errors in importing the functions
  • I called the functions from the excel cell, "=exponent(A1,B1)"

Instead of getting a result, I'm getting "Object Required" I don't know what went wrong?

Any ideas what I'm missing? Forgive me for the basic question.

like image 787
Vivek Avatar asked Jul 15 '17 07:07

Vivek


People also ask

How do I run Python Xlwings?

Call Python with “RunPython”In the VBA Editor ( Alt-F11 ), write the code below into a VBA module. xlwings quickstart automatically adds a new module with a sample call. If you rather want to start from scratch, you can add a new module via Insert > Module .

How do I import Xlwings into Python?

Call Python from Excel 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.

What can you do with Xlwings?

Xlwings can be used to insert data in an Excel file similarly that it reads from an Excel file. Data can be provided as a list or a single input to a certain cell or a selection of cells.

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).


1 Answers

You need to add the Reference in VBA.
Open up the Developer console (Alt-F11) Click on Tools -> References and select xlwings

like image 143
ajaali Avatar answered Sep 17 '22 22:09

ajaali