Skip to content

Writing to Different Cell When Calling UDF #2409

Open
@jordans114

Description

@jordans114

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions