Property or method not found: Sheets. (upon file re-opening)

I wrote a libreoffice BASIC macro function under My Macro & Dialogs -> Standard -> Module1. It envokes .Sheets() method:

Function tester(n As Long) 
 	tester = ThisComponent.Sheets(n).GetName 
End Function

If I did’t reopen the file, everything went right. Writing =tester(0) in a cell gives Sheet1, the default sheet name, correctly.

However, the following error message appears every time upon reopening the saved .ods file.

BASIC Runtime Error: Property or method not found: Sheets.

And it disappears after re-typing the saved formula.

I would like to know: (1) What causes this, and (2) How can I still use Sheets() or other worksheet function such as Sheet() without this trouble IN GENERAL? Thanks!

version: Libreoffice Calc 5.0.5.2
OS: win10 x64

Get the same problem when I do the same as you.

Works OK if I put the function macro in a module in the calc sheet and not in the main standard module.

This problem has been reported in Bug 79588.

I did test on my system, xubuntu LO v5.1.2.2 & had no problems whether the code was in My Macro & Dialogs -> Standard -> Module1 or a module in the sheet.