Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing to Different Cell When Calling UDF #2409

Open
jordans114 opened this issue Mar 3, 2024 · 1 comment
Open

Writing to Different Cell When Calling UDF #2409

jordans114 opened this issue Mar 3, 2024 · 1 comment

Comments

@jordans114
Copy link

OS: Windows 11
xlwings: 0.29.1
Excel: Version 2401 (Build 17231.20236)
Python: 3.11.8

I am using xlwings to make API calls, but I am only allowed to make a certain number per day.

When I call one of my api UDFs, I want them to also increment a different cell to keep track of how many times I have made an API call. My code looks something like this:

def api_call(url):
# Makes the API call, implementation not important. Returns data as str
return data

def get_information(item_id):
xw.Book('my_spreadsheet.xlsm').sheets['sheet_name']['A1'].value += 1
return api_call(item_id)

@xw.func
def GET_INFORMATION(item_id):
return get_information(item_id=item_id)

When I call GET_INFORMATION(item_id) in Excel, the following is returned:
"Application-defined or object-defined error"

Is there a way to do this properly?

@johodh
Copy link

johodh commented May 2, 2024

+1 on this, cant get it working either with the same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants