long running UDF and waiting OLE
Apologies if this is discussed elsewhere but I haven;t been able to find it if it is. I'll be brief.
A UDF that takes a relatively long time to return can do so after Excel has started to warn about
"Microsoft Excel is waiting for another application to complete an OLE action",
after this point it seems that the python side of things has a problem with returning data to Excel.
I have seen suggestions to use DisplayAlert and the like but this doesn't seem to work. What has worked for me though is co registering a message filter and wrapping up the UDF as follows:
Private Declare Function CoRegisterMessageFilter Lib "OLE32.DLL" (ByVal IFilterIn As Long, ByRef IPreviousFilter) As Long
Function LongRunMyPyUDF(args)
Dim IMsgFilter As Long
CoRegisterMessageFilter 0&, IMsgFilter
LongRunMyPyUDF = MyPyUDF(args) ---> calls the xlwings generated UDF
CoRegisterMessageFilter IMsgFilter, IMsgFilter
Exit Function
End Function
which does appear to work as expected.
It doesn't seem like the mechanism exists anywhere to handle this in a better manner, is there a better way to do this? Should I be doing something else? If not could there be an option within xlwings itself to achieve this sort of behavior. I'm thinking manually adding a wrapper spoils the joys of an otherwise nice deployment. My understanding of all of this stuff is patchy at best, so any advice would be appreciated.
app.display_alerts = False should do, see: https://github.com/xlwings/xlwings/issues/120