View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default VBA code ok in Excel 2003, but crashes Excel 2002 & 2000

You said to use KeyUp "for any routine that will lead to changing the
active sheet."
Is that do to something inherent with the KeyUp behavior?


I suspect, more likely the problem relates to the changing state of the
control while no longer on the active sheet.

How did you know this?


I've been hit by that before, and other issues over the years. There was
much more to contend with in XL97 but it seems newer versions become less
susceptible to such problems.

FWIW, although changing focus within the active sheet in the KeyDown event
works, it might be worth moving everything to the KeyUp

Regards,
Peter T

"tomgreen1000" wrote in message
...
Peter, thank you so much!!! KeyUp works not only in this simple example

but
also the legacy program that I am trying to support. The setting of focus
(when the control already had focus) and the ScreenUpdating are remnants

of
this much more complicated code. I left them in the simple example

because I
put it together in such a hurry.

You said to use KeyUp "for any routine that will lead to changing the

active
sheet." Is that do to something inherent with the KeyUp behavior? How

did
you know this?

Thanks again! You have solved a week of frustration.

Regards,

Tom


"Peter T" wrote:

Hi Tom,

I haven't tried it but slightly surprised it even works in XL2003. Try
changing

Private Sub CommandButton1_KeyDown(

to
Private Sub CommandButton1_KeyUp(


- for any routine that will lead to changing the active sheet. Notice if

you
press the Space key, which fires the click event, it only runs on KeyUp.

If you particularly prefer KeyDown for the other Case's, for the Case
Enter-key to activate another sheet, call code to do that in macro in an
ordinary module but called with the OnTime method.

In passing,
TextBox1_KeyDown includes TextBox1.Activate
and
CommandButton1_KeyDown includes CommandButton1.Activate

Why, when the respective controls already have focus.

In the snippet you posted there's no need to disable Screenupdating

Regards,
Peter T