I have created a dialog with some buttons.
I assigned a macro to each button (all macros send to a different sheet of the document, kind of "Go to Sheet 1, Sheet2, and so on).
The macros runs, but i need that clicking on a button, besides activating the macro (sending the the selected sheet), should also close the dialog containing the buttons,which does not happen.
Thanks.
[Solved] Start macro from button in dialog and close dialog
[Solved] Start macro from button in dialog and close dialog
Last edited by robleyd on Tue Jan 07, 2020 1:08 am, edited 2 times in total.
Reason: Add green tick
Reason: Add green tick
openoffice 4.16 linux/windows 10
Re: Start macro from button in a dialog and close the dialog
You can put YourDialogName.endexecute after your button code or you can change the Button type from default to OK
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Start macro from button in a dialog and close the dialog
Thanks for your answer.
OK type on button close dialog but does not execute macros
What you mean by "put YourDialogName.endexecute after your button code"? Button has no code in dialog, and adding YourDialogName.endexecute (which in my case is dlgScegli.endexecute) in the code of macros started by buttons gives error message (variable not defined).
OK type on button close dialog but does not execute macros
What you mean by "put YourDialogName.endexecute after your button code"? Button has no code in dialog, and adding YourDialogName.endexecute (which in my case is dlgScegli.endexecute) in the code of macros started by buttons gives error message (variable not defined).
openoffice 4.16 linux/windows 10
Re: Start macro from button in a dialog and close the dialog
If you use the okay button you need to put your code somewhere like the mouse pressed event.
For a normal button (the better option) you use a function to return your dialog name (loaddialog) which you store at the top of the module, you can then use it to call .endexecute.
See attached writer document with this implemented.
Edit: corrected can't use msgbox with okay button changed above and in document
For a normal button (the better option) you use a function to return your dialog name (loaddialog) which you store at the top of the module, you can then use it to call .endexecute.
See attached writer document with this implemented.
Code: Select all
REM ***** BASIC *****
dim dialogname
sub loaddialog1
dialogname = loaddialog("Standard","Dialog1")
dialogname.execute
end sub
Sub OkayButtonMousePressed
dialogname.model.title = "okay button"
End Sub
Sub OrdinaryButtonExecute
msgbox "ordinary button"
dialogname.endexecute
End Sub
Function LoadDialog(oLibraryName as String, oDialogName as String)
Dim oLib as Object
DialogLibraries.LoadLibrary(oLibraryName)
oLib = DialogLibraries.GetByName(oLibraryname)
LoadDialog() = CreateUnoDialog(oLib.GetByName(oDialogName))
End Function
- Attachments
-
- dialog close.odt
- (10.85 KiB) Downloaded 229 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Start macro from button in a dialog and close the dialog
Assign the button type property to an OK button and a Cancel button. Both buttons will close the dialog and let the execute method return 1 or 0.
The execute method returns 1 if a button of type "OK button" has been pressed.
The execute method returns 0 if a button of type "Cancel button" has been pressed or the dialog has been closed by the [x] button in the title bar.
Code: Select all
REM ***** BASIC *****
dim dialogname
sub loaddialog1
dialogname = loaddialog("Standard","Dialog1")
x = dialogname.execute
if x = 1 then
do_this
else
do_that
endif
REM the dialog will be closed now
end sub
The execute method returns 0 if a button of type "Cancel button" has been pressed or the dialog has been closed by the [x] button in the title bar.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Start macro from button in a dialog and close the dialog
The other way to get the dialog is from the event
Code: Select all
sub button_execute(ev) 'call with button execute or other event
'your code
ev.source.getcontext.endexecute
end sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Start macro from button in a dialog and close the dialog
All solutions worked fine. Thanks to all of you.
openoffice 4.16 linux/windows 10