How to close running dialog box via macro

I’m attempting to close a dialog named oDlg with the code below. oDlg is defined as a public object variable as I’m attempting to close a dialog that is created by another sub. I have tried killdlg as both private and public which makes no difference. Not sure what I’m doing wrong. I appreciate any input. Obviously, I"m a LO basic noob.

Thanks in advance.

Sub Close_dialog

killdlg= createUnoService("")

End Sub

Try oDlg.dispose()

Sorry that will work but may cause other problems. It depends on how you start the dialog. If oDlg.execute then


will work. If you’re using setVisible then see this answer for a possible solution non-modal dialog.

Obviously, in order to do this the dialog must be modeless (non-modal) and it’s possible to start a modeless dialog with either method.

A note for general knowledge, when using the endExecute method, make sure the object exists first. For example:

Sub CloseDlg
   If Not IsNull(oDlg) then
   End If
End Sub

I couldn’t get that command to work. It closed the entire application for some reason. More likely to be my code and not your command causing the problem. As it turns out, I ended up going another direction with my macro, so I didn’t press the issue. I have no doubt your answer is correct, given our previous encounters. Therefore, I’ll mark my question as answered. Thanks, Ratslinger. Docbda

Oops! I didn’t see that you edited your answer before sending my last comment. I was using “setVisible.” I’ll check out the link you sent. Thanks for the follow-up. Docbda

Not a problem. If you’re still having problems, please provide details. I’ll be glad to help you work out the details. It looks like a viable solution.

I do have a more general question regarding the code that I was initially trying. Due to the fact that the endExecute() is an function under the interface, why do I not need to create the Uno service before calling the endExecute() function? Note: I put this question here because it references the code that I included as part of my original question.

You don’t. Here’s my running test:

 Sub CloseDlg
 End Sub

I simply call this from a push button and it works fine with oDlg being global or Public. All else done when oDlg was created. In other words. endExecute is a method of the dialog object. You can see this with Mri.

I see. Thanks for the explanation. Looks like I need to download Mri and learn how to use it. This is similar to Xray, right?

They are both similar. I prefer Mri (I have both) but you can do the same with Xray - just inspect oDlg when it is active.