ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Prevent Escape on Nonmodal Userform with Progressbar (https://www.excelbanter.com/excel-programming/418335-prevent-escape-nonmodal-userform-progressbar.html)

Lazzaroni

Prevent Escape on Nonmodal Userform with Progressbar
 
Is there any way to use a progressbar control in a modal userform?

I need to block users from accessing Excel or interrupting code execution by
pressing Escape
while a progressbar is being displayed.

Pressing Escape while a nonmodal userform is active returns €śCode execution
has been interrupted.€ť Pressing Escape while a modal userform is active does
the same thing as the Cancel button if a Cancel button control is present.

I tried capturing the keydown event with the following code, but the code
gets interrupted before it can capture the keycode:
Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = vbKeyEscape Then Unload Me
End Sub

Either I need to be able to display a progressbar control in a modal
userform, or I need to be able to capture the Escape KeyDown event.

Thanks for your help.

Andym

Prevent Escape on Nonmodal Userform with Progressbar
 
Have you tried using the following line of code?
Application.EnableCancelKey = xlDisabled

This stops Ctrl+Break from interrupting code execution and I think it will
work in your case as well.

Andy

"Lazzaroni" wrote:

Is there any way to use a progressbar control in a modal userform?

I need to block users from accessing Excel or interrupting code execution by
pressing Escape
while a progressbar is being displayed.

Pressing Escape while a nonmodal userform is active returns €śCode execution
has been interrupted.€ť Pressing Escape while a modal userform is active does
the same thing as the Cancel button if a Cancel button control is present.

I tried capturing the keydown event with the following code, but the code
gets interrupted before it can capture the keycode:
Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = vbKeyEscape Then Unload Me
End Sub

Either I need to be able to display a progressbar control in a modal
userform, or I need to be able to capture the Escape KeyDown event.

Thanks for your help.


Lazzaroni

Prevent Escape on Nonmodal Userform with Progressbar
 
Andy:

Private Sub UserForm_Activate()
With Application
.Interactive = False
.EnableCancelKey = xlDisabled
End With
End Sub

The above code approximates a modal form, which is what I needed.

I would have liked to allow the user to use the Escape key in addition to
being able to click on the Cancel button, but EnableCancelKey = xlDisabled
prevents me from trapping the keycode as well, so the following code does not
work.

Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = vbKeyEscape Then Unload Me
End Sub

I will try looking for a EnableCancelKey = xlErrorHandler workaround, but
ideally, I would like to run my user form with ShowModal = True.
Unfortunately, I havent found a way to display a progressbar control
correctly in a modal userform.

For the time being, this does the trick. Thank you for your suggestion.


All times are GMT +1. The time now is 11:41 AM.

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