ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Handling Dialog Boxes (https://www.excelbanter.com/excel-programming/390276-handling-dialog-boxes.html)

djExcel

Handling Dialog Boxes
 
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.

Nigel

Handling Dialog Boxes
 
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

--
Cheers
Nigel



"djExcel" wrote in message
...
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.




Tom Ogilvy

Handling Dialog Boxes
 
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.

--
Regards,
Tom Ogilvy

"Nigel" wrote:

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

--
Cheers
Nigel



"djExcel" wrote in message
...
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.





Nigel

Handling Dialog Boxes
 
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.

--
Cheers
Nigel



"Tom Ogilvy" wrote in message
...
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.

--
Regards,
Tom Ogilvy

"Nigel" wrote:

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

--
Cheers
Nigel



"djExcel" wrote in message
...
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.








All times are GMT +1. The time now is 12:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com