View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Lazzaroni Lazzaroni is offline
external usenet poster
 
Posts: 55
Default 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.