ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Disable Cancel button (https://www.excelbanter.com/excel-programming/290744-disable-cancel-button.html)

R Avery

Disable Cancel button
 
Is there anyway to cancel the "X" cancel button at the top of UserForms?
Alternatively, is there a way to re-route the "Esc" key to the "Done" button
on my userform?

The problem is that I have code that calls this form, and does an infinite
loop while checking the form's "IsDone" custom property. When the user
cancels the form, I get an "Automation Error", because the code calling the
form is still looking for a .IsDone property, but the object no longer
exists! I have tried putting setting the IsDone property to TRUE in the
Terminate event... but it does not work.

Or, is there another solution to this problem that I do not know about? Any
help would be appreciated!



Chip Pearson

Disable Cancel button
 
You can disable the 'X' button with the following code:

Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
Cancel = True
End Sub

You can make your Done button respond to the Esc key by setting
the Cancel property of the button to True.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"R Avery" wrote in message
...
Is there anyway to cancel the "X" cancel button at the top of

UserForms?
Alternatively, is there a way to re-route the "Esc" key to the

"Done" button
on my userform?

The problem is that I have code that calls this form, and does

an infinite
loop while checking the form's "IsDone" custom property. When

the user
cancels the form, I get an "Automation Error", because the code

calling the
form is still looking for a .IsDone property, but the object no

longer
exists! I have tried putting setting the IsDone property to

TRUE in the
Terminate event... but it does not work.

Or, is there another solution to this problem that I do not

know about? Any
help would be appreciated!





R Avery

Disable Cancel button
 
Perfect. Thanks!




All times are GMT +1. The time now is 05:52 PM.

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