How to load a document library BEFORE the formulas read from the file are parsed?

Formulas calling user code from a document library report the #NAME? errror. If reentered after any process loading the library they are parsed again and return the expected results.
I didn’t succeed with attempts to load the library in time using event handlers - and didn’t actually expect success…

maybe this: 143989 – calling python from calc user function fails at document load ?

Thanks!" Seems to be the same problem though I tried it with Basic UDF.

My sloppy and inefficient workaround:

Sub reparseAgainst_525()
ThisComponent.BasicLibraries.LoadLibrary("Lupprary")
For Each sheet In ThisComponent.Sheets
 rgs = sheet.queryContentCells(16)
 For Each rg In rgs
  uR = rg.Rows.Count - 1 : uC = rg.Columns.Count - 1
  For r = 0 To uR
   For c = 0 To uC
    rc_cell = rg.getCellByPosition(c, r)
    If rc_cell.Error=525 Then '"#NAME?"
     rc_fo = rc_cell.Formula
     rc_cell.String = ""
     rc_cell.Formula = rc_fo
    EndIf
   Next c
  Next r
 Next rg
Next sheet 
End Sub

Hello, Wolfgang!
Maybe we can try this?

Clever idea!
However, it requires a modification to the call of the “main” function - as far as I see at every occurrence.
And the modification must regard the type of the primary result.

Just add CheckLib() to the beginning of each UDF function.

1 Like

Yes.
However, I have tried to find a workaround that does not interfere with moving functions (UDF) between multiple libraries contained in the document. This requires not needing to know which library a UDF is stored to. In addition the UDFs shouldn’t need a specific line of code checking the state.
The solution I have outlined has a lot more code lines, but only the event handler onViewCreated() or its helper reparseAgainst_525() need to know the names of the document libraries that must be loaded. With 'ThisComponent.getLibraryContainer().ElementNames` you can load all document libraries at this point.
See example:
crazy.ods (19.0 KB)
See also tdf#164477

1 Like

Interface XStarBasicAccess is deprecated. Better to use BasicLibraries:

Msgbox Join(BasicLibraries.ElementNames, Chr(10))
1 Like