Reputation: 468
I am trying to implement a UDF through xlwings, from an existent python script which implements win32com.client.
The script is successful if ran from shell, but fails with an "Automation error" if called from the correspondent UDF.
Through debug I found that the error arises from trying to set a new value for sel_range.Interior.Color
, where sel_range
is a Range object from the active worksheet (from win32com.client).
In particular the exception is raised from Python38-32\Lib\site-packages\win32com\client\__init__.py
, line 482, when trying to call self._oleobj_.Invoke(*(args + (value,) + defArgs))
.
Comparing the run from shell and the one from UDF, all the objects and arguments are the same.
Unfortunately I can not debug further within the Invoke, and I am just starting with COM objects.
Does anyone has an idea what the issue could be? Why the Invoke of the oleobj has such a different behavior? The base script is entirely based on win32com, and from xlwings I use just the add in with the xw.func decorator.
EDIT I found out that this is indeed a desired behavior of xlwings, and ranges are not settable within UDF. Is there any workaround? Something equivalent.
Upvotes: 0
Views: 248
Reputation: 468
Since it seems to be a major Excel design, I moved the logic of my function to be a macro, and assign it to a button.
Upvotes: 1