Handling Dialog Boxes

G

Guest

Hello,

Is there an easy way to disable close-button (that X in upper right corner)
in dialog boxes or any easy way to handle a case when user clicks it?

And an other question. How can I disable OnChange-event to execute, when I
set up the values on a dialog box?

Thank You for Your answers.
 
N

Nigel

If you are referring to userforms then you can handle the user clicking
large X by including the QueryClose event

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then Cancel = True
End Sub

The above simply ignores the user pressing large X; if you wish to disable
or remove the status bar altogether then you will need to include an API
call, if you need this repost for more information.

To disable events use Application.EnableEvents = False
after updating re-enable them with Application.EnableEvents = True
 
G

Guest

Let me add some information on the suppression of events.

Using the same assumption, that the OP is talking about Userforms, then
application.EnableEvents has no effect on events for Control Toolbox Controls
used on the userform and their related events (those in the Userform module).
Application.EnableEvents is part of the Excel library. Control Toolbox
controls are part of the MSforms library. There is no single command to
disable these events. You have to program each event to look at specific
conditions and avoid running any inappropriate code if the conditions so
warrant.

If the OP was actually talking about Excel events such as worksheet_change,
then you are absolutely correct that that the enableevents command will
suppress these.
 
N

Nigel

Hi Tom
Your clarification will help the OP who I suspect is talking about userform
events. So the suggestion would be to have conditional statements in the
OnChange events of controls on the userform code where, if in edit mode, the
event when triggered is ignored otherwise it the event runs normally.

Private Sub ComboBox1_Change()

If eMode = True Then Exit Sub

' code here runs if not in edit mode

End Sub

Variable eMode is set to True before the control is updated; and set False
afterwards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top