It seems Calc tries to execute user-defined functions before the document is fully loaded. If the function has a reference to ActiveSheet, Calc will throw “object variable not set” errors while loading.
As an example, below function returns the index of “this sheet”. The function works fine if the document is already loaded, but throws an error when the document is being opened.
function getSheetIndex() as integer Dim oSheet As Object : oSheet = ThisComponent.CurrentController.ActiveSheet getSheetIndex = oSheet.RangeAddress.Sheet end function
The errors don’t crash or freeze the application, they just display an error dialog that needs to be closed for the document to resume loading. So the document will eventually load, but depending on the number of user-defined functions, this may require a lot of clicking. And when the document is fully loaded and displayed, Calc will not auto-recalculate those functions, so I have to manually recalculate each one of them (even though Calc is set to autocalculate).
How can I avoid this error? Is there a way to delay the execution of custom functions until the document is fully loaded? Is my function wrong?
I’m using LO 22.214.171.124, downloaded from the LO website, on Linux MInt 19.3