Ask Your Question
0

I get An exception occurred Type: com.sun.star.container.NoSuchElementException Message

asked 2021-01-12 14:16:06 +0100

Batbloke gravatar image

updated 2021-01-12 16:21:58 +0100

erAck gravatar image

I completely stripped LibreOffice and all user data from my PC and reinstalled. So, a completely fresh 6.4.7.2 install. As a test I then I created an empty Calc sheet. In Macros organiser I created a new Module 1 within the sheet (not in MyMacros) as I want to be able to send the sheet to another PC with a working macro. I then created a dialog under the new "sheet" module. I then wrote this code:

Sub Main

    Dim Dialog as Object 

    Dim Label as Object

    GlobalScope.BasicLibraries.LoadLibrary("Tools") 

    Dialog = LoadDialog("Standard", "Dialog1")

    Label = Dialog.GetControl("Label1")

    Label1.Text = "YES!"

End Sub

Running the macro from a double click event on the sheet - I get: BASIC runtime error. An exception occurred Type: com.sun.star.container.NoSuchElementException Message: .

within:

Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer)

Dim oLib as Object

Dim oLibDialog as Object

Dim oRuntimeDialog as Object

    If IsMissing(oLibContainer ) then

        oLibContainer = DialogLibraries

    End If

    oLibContainer.LoadLibrary(LibName)

    oLib = oLibContainer.GetByName(Libname)

    oLibDialog = oLib.GetByName(DialogName)

    oRuntimeDialog = CreateUnoDialog(oLibDialog)

    LoadDialog() = oRuntimeDialog

End Function

It fails at oLibDialog = oLib.GetByName(DialogName)

I have been informed that the only way to send a Calc sheet with working macros (and dialogs) is to put all macros and dialogs "under" the sheet in the Macro organiser - but I constantly find (even with this utterly fresh test approach) that it fails, it appears to require everything to be in MyMacros to work but if I do that the sheet is empty of macros and dialogs when sent (emailed). I really need to be able to distribute my work to other PCs but this is preventing me. Any pointers please as to what I am doing wrong.

[erAck: edited to properly mark code blocks as code; please do so by selecting a code block and hitting Ctrl+K which indents by 4 spaces to format, thanks.]

edit retag flag offensive close merge delete

Comments

Try Dialog = LoadDialog("Standard", "Dialog1", DialogLibraries) (I hope that you also created a dialogue with the name Dialog1, you did not write about it)

JohnSUN gravatar imageJohnSUN ( 2021-01-12 14:50:02 +0100 )edit

Thanks John. At first I thought this had cracked it. But looking at the LoadDialog code it sets this to DialogLibraries as default if missing. It still fails the same as before. I think it is looking in the wrong "Standard" container

Batbloke gravatar imageBatbloke ( 2021-01-12 17:13:15 +0100 )edit

Right, different value of DialogLibraries, varies depending on the context - called from your ThisComponent or called from subroutine in the library Tools (level office macros)

JohnSUN gravatar imageJohnSUN ( 2021-01-12 21:27:11 +0100 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2021-01-13 16:26:36 +0100

Batbloke gravatar image

Okay, I now have it working. Thanks to John Sun for the help and others for formatting my question correctly.

Rather than using LoadDialog I found the following worked:

moMMDialog = CreateUnoDialog(DialogLibraries.BRWLibrary.dlgMainMenu)

where BRWLibrary is a library containing my dialogs I created "within" the sheet

Thanks

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2021-01-12 14:16:06 +0100

Seen: 22 times

Last updated: Jan 13