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

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

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

oLib = oLibContainer.GetByName(Libname)

oLibDialog = oLib.GetByName(DialogName)

oRuntimeDialog = CreateUnoDialog(oLibDialog)

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 close merge delete

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

( 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

( 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)

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

Sort by » oldest newest most voted

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

more