Ask Your Question
0

How to close running dialog box via macro

asked 2016-04-14 00:21:38 +0200

docbda gravatar image

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("com.sun.star.awt.XDialog")
oDlg.killdlg.endexecute()

End Sub
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2016-04-14 00:50:37 +0200

Ratslinger gravatar image

updated 2016-04-14 19:18:18 +0200

Try oDlg.dispose()

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

oDlg.endExecute()

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
       oDlg.endExecute()
   End If
End Sub
edit flag offensive delete link more

Comments

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

docbda gravatar imagedocbda ( 2016-04-14 17:20:21 +0200 )edit

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

docbda gravatar imagedocbda ( 2016-04-14 17:27:15 +0200 )edit

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.

Ratslinger gravatar imageRatslinger ( 2016-04-14 18:06:05 +0200 )edit

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 com.sun.star.awt.XDialog 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.

docbda gravatar imagedocbda ( 2016-04-14 18:28:39 +0200 )edit

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

 Sub CloseDlg
    oDlg.endExecute()
 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.

Ratslinger gravatar imageRatslinger ( 2016-04-14 18:48:19 +0200 )edit

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?

docbda gravatar imagedocbda ( 2016-04-14 19:29:07 +0200 )edit

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.

Ratslinger gravatar imageRatslinger ( 2016-04-14 20:01:40 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-04-14 00:21:38 +0200

Seen: 1,832 times

Last updated: Apr 14 '16