Why does this code not work?

J

John Keith

Attempting to make the regular enter key behave as if you press Alt-Enter, in
responce to someones post about how to do this.

Pressing the standard enter key (not the numeric keypad enter) causes an
infinite loop. The screen flickers with an hour-glass after pressing enter.
Ctrl-Break stops the code and it is always on the Sub AltEnterRtn() line.

Can anyone explain what is going on behind the scenes that causes this?

Sub SetKey()
Application.OnKey "~", "AltEnterRtn"
End Sub
Sub ResetKey()
Application.OnKey "~"
End Sub
Sub AltEnterRtn()
Application.SendKeys "%~", True
End Sub
 
G

galimi

It's getting caught in an infinite loop because after recognizing the enter
key, it is processing another enter routine, creating the loop.
 
J

John Keith

It does seem that way, but
Wouldn't I have to have had
Sub SetKey()
Application.OnKey "~", "AltEnterRtn"
Application.OnKey "%~", "AltEnterRtn"
End Sub

For the Sendkeys forcing an Alt-Enter to then cause the loop?
The Sendkeys (alt-Enter) should not be causing the OnKey for the standalone
Enter to fire. Or its that I don't understand what OnKey is doing in this
case. (Probably so since everyday I find out how much more there is that I
dont know.)

Can you think of a way to get around this loop, so that pressing Enter will
cause an in-cell line break instead of having to use Alt-Enter?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top