Basic can´t open dialog at first try

Hi!
I am trying to open a dialog from a Button.
The function called is this one:

Sub OpenDialog
    Dim oDialog as Object
    oDialog = CreateUnoDialog(ThisComponent.DialogLibraries.getByName("Standard").getByName("Dialog1"))
    oDialog.Execute()
End Sub

The problem: When I load the documents and I click the Button, an error is produced:

BASIC runtime error.
An exception occurred
Type: com.sun.star.lang.WrappedTargetException
Message:
TargetException:
Type: com.sun.star.script.LibraryNotLoadedException
Message: .

If after the error, I click the Button again, everything works as expected.
If instead of clicking the button after load, I Run the function through Basic macro editor´s Run button, it works even at first try.
So…what is going on?
Could you please help me with that?
Thank you!
Untitled 1.ods (13.5 KB)

Sub OpenDialog
    oLibs = ThisComponent.DialogLibraries
    oLibs.loadLibrary("Standard")
    oDialog = CreateUnoDialog(oLibs.getByName("Standard").getByName("Dialog1"))
    oDialog.Execute()
End Sub

Thank you very much! :heart: