Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default OnKey problem

I'm using Excel 2003 in Vista. I'm using the following code, but it doesn't
work.
Application.OnKey "^{+}", "Placenm"
I've placed it in ThisWorkBook in a WorkBook_Open routine.
I've also placed it in a subroutine that gets called periodically in the
course of a work session.
I've also tried different key combinations. Nothing seems to work. (The
subroutine, "Placenm" is not getting called.)
Any suggestions would be appreciated.
Thanks.
Bert.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default OnKey problem

Remember:

1. CNTRL-+ using the numeric keypad will not work
2. to get to the "normal" + key ( the one above the = sign) you must touch
CNTRL-SHFT-=

This key combination will drive your macro!
--
Gary''s Student - gsnu2007k


"Bert" wrote:

I'm using Excel 2003 in Vista. I'm using the following code, but it doesn't
work.
Application.OnKey "^{+}", "Placenm"
I've placed it in ThisWorkBook in a WorkBook_Open routine.
I've also placed it in a subroutine that gets called periodically in the
course of a work session.
I've also tried different key combinations. Nothing seems to work. (The
subroutine, "Placenm" is not getting called.)
Any suggestions would be appreciated.
Thanks.
Bert.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default OnKey problem

Thanks; however, as noted, I've tried several different key combinations--
"%n", "^{+}", and others.
I've tried all control and alt keys in all combinations (with and without
the shift keys)
It still isn't working.
Any other suggestions?
Bert

"Gary''s Student" wrote in message
...
Remember:

1. CNTRL-+ using the numeric keypad will not work
2. to get to the "normal" + key ( the one above the = sign) you must touch
CNTRL-SHFT-=

This key combination will drive your macro!
--
Gary''s Student - gsnu2007k


"Bert" wrote:

I'm using Excel 2003 in Vista. I'm using the following code, but it
doesn't
work.
Application.OnKey "^{+}", "Placenm"
I've placed it in ThisWorkBook in a WorkBook_Open routine.
I've also placed it in a subroutine that gets called periodically in the
course of a work session.
I've also tried different key combinations. Nothing seems to work. (The
subroutine, "Placenm" is not getting called.)
Any suggestions would be appreciated.
Thanks.
Bert.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default OnKey problem

Where did you put Placenm?
--
Gary''s Student - gsnu200827


"Bert" wrote:

Thanks; however, as noted, I've tried several different key combinations--
"%n", "^{+}", and others.
I've tried all control and alt keys in all combinations (with and without
the shift keys)
It still isn't working.
Any other suggestions?
Bert

"Gary''s Student" wrote in message
...
Remember:

1. CNTRL-+ using the numeric keypad will not work
2. to get to the "normal" + key ( the one above the = sign) you must touch
CNTRL-SHFT-=

This key combination will drive your macro!
--
Gary''s Student - gsnu2007k


"Bert" wrote:

I'm using Excel 2003 in Vista. I'm using the following code, but it
doesn't
work.
Application.OnKey "^{+}", "Placenm"
I've placed it in ThisWorkBook in a WorkBook_Open routine.
I've also placed it in a subroutine that gets called periodically in the
course of a work session.
I've also tried different key combinations. Nothing seems to work. (The
subroutine, "Placenm" is not getting called.)
Any suggestions would be appreciated.
Thanks.
Bert.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default OnKey problem

Placenm is in the "default" module "Module1".
Bert

"Gary''s Student" wrote in message
...
Where did you put Placenm?
--
Gary''s Student - gsnu200827


"Bert" wrote:

Thanks; however, as noted, I've tried several different key
combinations--
"%n", "^{+}", and others.
I've tried all control and alt keys in all combinations (with and without
the shift keys)
It still isn't working.
Any other suggestions?
Bert

"Gary''s Student" wrote in
message
...
Remember:

1. CNTRL-+ using the numeric keypad will not work
2. to get to the "normal" + key ( the one above the = sign) you must
touch
CNTRL-SHFT-=

This key combination will drive your macro!
--
Gary''s Student - gsnu2007k


"Bert" wrote:

I'm using Excel 2003 in Vista. I'm using the following code, but it
doesn't
work.
Application.OnKey "^{+}", "Placenm"
I've placed it in ThisWorkBook in a WorkBook_Open routine.
I've also placed it in a subroutine that gets called periodically in
the
course of a work session.
I've also tried different key combinations. Nothing seems to work.
(The
subroutine, "Placenm" is not getting called.)
Any suggestions would be appreciated.
Thanks.
Bert.







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default OnKey problem

I put the following in Module1:

Sub OffKey()
Application.OnKey "^{+}", "Placenm"
End Sub

Sub Placenm()
MsgBox ("Hello World")
End Sub

I went back to the worksheet and manually ran OffKey. I then touched
CNTRL-SHFT-+ and got the macro to fire.

Try the same on a fresh, new workbook.
--
Gary''s Student - gsnu200827


"Bert" wrote:

Placenm is in the "default" module "Module1".
Bert

"Gary''s Student" wrote in message
...
Where did you put Placenm?
--
Gary''s Student - gsnu200827


"Bert" wrote:

Thanks; however, as noted, I've tried several different key
combinations--
"%n", "^{+}", and others.
I've tried all control and alt keys in all combinations (with and without
the shift keys)
It still isn't working.
Any other suggestions?
Bert

"Gary''s Student" wrote in
message
...
Remember:

1. CNTRL-+ using the numeric keypad will not work
2. to get to the "normal" + key ( the one above the = sign) you must
touch
CNTRL-SHFT-=

This key combination will drive your macro!
--
Gary''s Student - gsnu2007k


"Bert" wrote:

I'm using Excel 2003 in Vista. I'm using the following code, but it
doesn't
work.
Application.OnKey "^{+}", "Placenm"
I've placed it in ThisWorkBook in a WorkBook_Open routine.
I've also placed it in a subroutine that gets called periodically in
the
course of a work session.
I've also tried different key combinations. Nothing seems to work.
(The
subroutine, "Placenm" is not getting called.)
Any suggestions would be appreciated.
Thanks.
Bert.






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default OnKey problem

Okay...when I closed the workbook (and Excel) and restarted it, it
worked--both your code and mine. (Actually, I'm using Alt-n - "%n".) So
thanks for sticking with this!
Now I have another problem: When the insertion point is in a textbox in a
Userform, the OnKey method doesn't seem to work. It would appear that
Userforms behave differently. Is this the case? If so, is there a way to
trap specific keystokes in a textbox?
Thanks again.
Bert.

"Gary''s Student" wrote in message
...
I put the following in Module1:

Sub OffKey()
Application.OnKey "^{+}", "Placenm"
End Sub

Sub Placenm()
MsgBox ("Hello World")
End Sub

I went back to the worksheet and manually ran OffKey. I then touched
CNTRL-SHFT-+ and got the macro to fire.

Try the same on a fresh, new workbook.
--
Gary''s Student - gsnu200827


"Bert" wrote:

Placenm is in the "default" module "Module1".
Bert

"Gary''s Student" wrote in
message
...
Where did you put Placenm?
--
Gary''s Student - gsnu200827


"Bert" wrote:

Thanks; however, as noted, I've tried several different key
combinations--
"%n", "^{+}", and others.
I've tried all control and alt keys in all combinations (with and
without
the shift keys)
It still isn't working.
Any other suggestions?
Bert

"Gary''s Student" wrote in
message
...
Remember:

1. CNTRL-+ using the numeric keypad will not work
2. to get to the "normal" + key ( the one above the = sign) you must
touch
CNTRL-SHFT-=

This key combination will drive your macro!
--
Gary''s Student - gsnu2007k


"Bert" wrote:

I'm using Excel 2003 in Vista. I'm using the following code, but
it
doesn't
work.
Application.OnKey "^{+}", "Placenm"
I've placed it in ThisWorkBook in a WorkBook_Open routine.
I've also placed it in a subroutine that gets called periodically
in
the
course of a work session.
I've also tried different key combinations. Nothing seems to work.
(The
subroutine, "Placenm" is not getting called.)
Any suggestions would be appreciated.
Thanks.
Bert.







  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default OnKey problem

Use the TextBox's own KeyDown, KeyUp or KeyPress events depending on what
kind of keystroke you want to trap.

--
Rick (MVP - Excel)


"Bert" wrote in message
...
Okay...when I closed the workbook (and Excel) and restarted it, it
worked--both your code and mine. (Actually, I'm using Alt-n - "%n".) So
thanks for sticking with this!
Now I have another problem: When the insertion point is in a textbox in a
Userform, the OnKey method doesn't seem to work. It would appear that
Userforms behave differently. Is this the case? If so, is there a way to
trap specific keystokes in a textbox?
Thanks again.
Bert.

"Gary''s Student" wrote in
message ...
I put the following in Module1:

Sub OffKey()
Application.OnKey "^{+}", "Placenm"
End Sub

Sub Placenm()
MsgBox ("Hello World")
End Sub

I went back to the worksheet and manually ran OffKey. I then touched
CNTRL-SHFT-+ and got the macro to fire.

Try the same on a fresh, new workbook.
--
Gary''s Student - gsnu200827


"Bert" wrote:

Placenm is in the "default" module "Module1".
Bert

"Gary''s Student" wrote in
message
...
Where did you put Placenm?
--
Gary''s Student - gsnu200827


"Bert" wrote:

Thanks; however, as noted, I've tried several different key
combinations--
"%n", "^{+}", and others.
I've tried all control and alt keys in all combinations (with and
without
the shift keys)
It still isn't working.
Any other suggestions?
Bert

"Gary''s Student" wrote in
message
...
Remember:

1. CNTRL-+ using the numeric keypad will not work
2. to get to the "normal" + key ( the one above the = sign) you
must
touch
CNTRL-SHFT-=

This key combination will drive your macro!
--
Gary''s Student - gsnu2007k


"Bert" wrote:

I'm using Excel 2003 in Vista. I'm using the following code, but
it
doesn't
work.
Application.OnKey "^{+}", "Placenm"
I've placed it in ThisWorkBook in a WorkBook_Open routine.
I've also placed it in a subroutine that gets called periodically
in
the
course of a work session.
I've also tried different key combinations. Nothing seems to
work.
(The
subroutine, "Placenm" is not getting called.)
Any suggestions would be appreciated.
Thanks.
Bert.








  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default OnKey problem

Ah! Thanks, Rick!
Bert

"Rick Rothstein" wrote in message
...
Use the TextBox's own KeyDown, KeyUp or KeyPress events depending on what
kind of keystroke you want to trap.

--
Rick (MVP - Excel)


"Bert" wrote in message
...
Okay...when I closed the workbook (and Excel) and restarted it, it
worked--both your code and mine. (Actually, I'm using Alt-n - "%n".) So
thanks for sticking with this!
Now I have another problem: When the insertion point is in a textbox in
a Userform, the OnKey method doesn't seem to work. It would appear that
Userforms behave differently. Is this the case? If so, is there a way
to trap specific keystokes in a textbox?
Thanks again.
Bert.

"Gary''s Student" wrote in
message ...
I put the following in Module1:

Sub OffKey()
Application.OnKey "^{+}", "Placenm"
End Sub

Sub Placenm()
MsgBox ("Hello World")
End Sub

I went back to the worksheet and manually ran OffKey. I then touched
CNTRL-SHFT-+ and got the macro to fire.

Try the same on a fresh, new workbook.
--
Gary''s Student - gsnu200827


"Bert" wrote:

Placenm is in the "default" module "Module1".
Bert

"Gary''s Student" wrote in
message
...
Where did you put Placenm?
--
Gary''s Student - gsnu200827


"Bert" wrote:

Thanks; however, as noted, I've tried several different key
combinations--
"%n", "^{+}", and others.
I've tried all control and alt keys in all combinations (with and
without
the shift keys)
It still isn't working.
Any other suggestions?
Bert

"Gary''s Student" wrote in
message
...
Remember:

1. CNTRL-+ using the numeric keypad will not work
2. to get to the "normal" + key ( the one above the = sign) you
must
touch
CNTRL-SHFT-=

This key combination will drive your macro!
--
Gary''s Student - gsnu2007k


"Bert" wrote:

I'm using Excel 2003 in Vista. I'm using the following code, but
it
doesn't
work.
Application.OnKey "^{+}", "Placenm"
I've placed it in ThisWorkBook in a WorkBook_Open routine.
I've also placed it in a subroutine that gets called periodically
in
the
course of a work session.
I've also tried different key combinations. Nothing seems to
work.
(The
subroutine, "Placenm" is not getting called.)
Any suggestions would be appreciated.
Thanks.
Bert.









  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default OnKey problem

Thanks for getting me on the right track. Okay, I want to trap only Alt-n
(or possibly Ctrl-n) at this point, although later I may want to add other
similar combinations. All other keystrokes should be displayed or triggered
as usual (Ctrl-c, for example, should copy selected text).
I'm not sure this is right, but the following subroutine captures the Alt-n
keystrokes; however, I'm not sure how to "release" the non-Alt-n keystrokes
to do what they normally would.
----------------------------------------------
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Static half1 As Boolean
If half1 Then
' get second half of the key combination.
If KeyCode = 78 Then
Call Placenm ' add name at insertion point
End If
half1 = False
Else
' the next line works as long as the character is a displayable character.
' do I need to create code to handle each condition/keystroke?
If KeyCode = 18 Then
half1 = True
Else
TextBox1.Text = TextBox1.Text & Chr$(KeyCode)
End If
End If
End Sub
----------------------------------------------
Thanks.
Bert

"Rick Rothstein" wrote in message
...
Use the TextBox's own KeyDown, KeyUp or KeyPress events depending on what
kind of keystroke you want to trap.

--
Rick (MVP - Excel)


"Bert" wrote in message
...
Okay...when I closed the workbook (and Excel) and restarted it, it
worked--both your code and mine. (Actually, I'm using Alt-n - "%n".) So
thanks for sticking with this!
Now I have another problem: When the insertion point is in a textbox in
a Userform, the OnKey method doesn't seem to work. It would appear that
Userforms behave differently. Is this the case? If so, is there a way
to trap specific keystokes in a textbox?
Thanks again.
Bert.

"Gary''s Student" wrote in
message ...
I put the following in Module1:

Sub OffKey()
Application.OnKey "^{+}", "Placenm"
End Sub

Sub Placenm()
MsgBox ("Hello World")
End Sub

I went back to the worksheet and manually ran OffKey. I then touched
CNTRL-SHFT-+ and got the macro to fire.

Try the same on a fresh, new workbook.
--
Gary''s Student - gsnu200827


"Bert" wrote:

Placenm is in the "default" module "Module1".
Bert

"Gary''s Student" wrote in
message
...
Where did you put Placenm?
--
Gary''s Student - gsnu200827


"Bert" wrote:

Thanks; however, as noted, I've tried several different key
combinations--
"%n", "^{+}", and others.
I've tried all control and alt keys in all combinations (with and
without
the shift keys)
It still isn't working.
Any other suggestions?
Bert

"Gary''s Student" wrote in
message
...
Remember:

1. CNTRL-+ using the numeric keypad will not work
2. to get to the "normal" + key ( the one above the = sign) you
must
touch
CNTRL-SHFT-=

This key combination will drive your macro!
--
Gary''s Student - gsnu2007k


"Bert" wrote:

I'm using Excel 2003 in Vista. I'm using the following code, but
it
doesn't
work.
Application.OnKey "^{+}", "Placenm"
I've placed it in ThisWorkBook in a WorkBook_Open routine.
I've also placed it in a subroutine that gets called periodically
in
the
course of a work session.
I've also tried different key combinations. Nothing seems to
work.
(The
subroutine, "Placenm" is not getting called.)
Any suggestions would be appreciated.
Thanks.
Bert.











  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default OnKey problem

Comment out your complete KeyDown event (so you won't lose it in case you
want to go back to it) and then put this demonstration KeyDown event code in
its place...

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If KeyCode = vbKeyN Then
If Shift = 1 Then
MsgBox "You pressed Shift+N"
ElseIf Shift = 2 Then
MsgBox "You pressed Ctrl+N"
ElseIf Shift = 4 Then
MsgBox "You pressed Alt+N"
Else
MsgBox "You pressed just N by itself"
End If
End If
End Sub

Now run the UserForm, place the cursor in the TextBox and press Shift+N,
then press Ctrl+N, then press Alt+N and then just press the N by itself.
Hopefully, the above code will help you to see how to work with this event
(the KeyUp event works the same way).

--
Rick (MVP - Excel)


"Bert" wrote in message
...
Thanks for getting me on the right track. Okay, I want to trap only Alt-n
(or possibly Ctrl-n) at this point, although later I may want to add other
similar combinations. All other keystrokes should be displayed or
triggered as usual (Ctrl-c, for example, should copy selected text).
I'm not sure this is right, but the following subroutine captures the
Alt-n keystrokes; however, I'm not sure how to "release" the non-Alt-n
keystrokes to do what they normally would.
----------------------------------------------
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Static half1 As Boolean
If half1 Then
' get second half of the key combination.
If KeyCode = 78 Then
Call Placenm ' add name at insertion point
End If
half1 = False
Else
' the next line works as long as the character is a displayable character.
' do I need to create code to handle each condition/keystroke?
If KeyCode = 18 Then
half1 = True
Else
TextBox1.Text = TextBox1.Text & Chr$(KeyCode)
End If
End If
End Sub
----------------------------------------------
Thanks.
Bert

"Rick Rothstein" wrote in message
...
Use the TextBox's own KeyDown, KeyUp or KeyPress events depending on what
kind of keystroke you want to trap.

--
Rick (MVP - Excel)


"Bert" wrote in message
...
Okay...when I closed the workbook (and Excel) and restarted it, it
worked--both your code and mine. (Actually, I'm using Alt-n - "%n".) So
thanks for sticking with this!
Now I have another problem: When the insertion point is in a textbox in
a Userform, the OnKey method doesn't seem to work. It would appear that
Userforms behave differently. Is this the case? If so, is there a way
to trap specific keystokes in a textbox?
Thanks again.
Bert.

"Gary''s Student" wrote in
message ...
I put the following in Module1:

Sub OffKey()
Application.OnKey "^{+}", "Placenm"
End Sub

Sub Placenm()
MsgBox ("Hello World")
End Sub

I went back to the worksheet and manually ran OffKey. I then touched
CNTRL-SHFT-+ and got the macro to fire.

Try the same on a fresh, new workbook.
--
Gary''s Student - gsnu200827


"Bert" wrote:

Placenm is in the "default" module "Module1".
Bert

"Gary''s Student" wrote in
message
...
Where did you put Placenm?
--
Gary''s Student - gsnu200827


"Bert" wrote:

Thanks; however, as noted, I've tried several different key
combinations--
"%n", "^{+}", and others.
I've tried all control and alt keys in all combinations (with and
without
the shift keys)
It still isn't working.
Any other suggestions?
Bert

"Gary''s Student" wrote in
message
...
Remember:

1. CNTRL-+ using the numeric keypad will not work
2. to get to the "normal" + key ( the one above the = sign) you
must
touch
CNTRL-SHFT-=

This key combination will drive your macro!
--
Gary''s Student - gsnu2007k


"Bert" wrote:

I'm using Excel 2003 in Vista. I'm using the following code,
but it
doesn't
work.
Application.OnKey "^{+}", "Placenm"
I've placed it in ThisWorkBook in a WorkBook_Open routine.
I've also placed it in a subroutine that gets called
periodically in
the
course of a work session.
I've also tried different key combinations. Nothing seems to
work.
(The
subroutine, "Placenm" is not getting called.)
Any suggestions would be appreciated.
Thanks.
Bert.










  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default OnKey problem

Sorry, I left out the most important statement...

KeyCode = 0

its the one that stops a character from being printed (usually used when one
presses Shift, Ctrl or Alt is pressed in combination with a letter in order
to stop the letter from appearing in the TextBox)...

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If KeyCode = vbKeyN Then
If Shift = 1 Then
MsgBox "You pressed Shift+N"
KeyCode = 0
ElseIf Shift = 2 Then
MsgBox "You pressed Ctrl+N"
KeyCode = 0
ElseIf Shift = 4 Then
MsgBox "You pressed Alt+N"
KeyCode = 0
Else
MsgBox "You pressed just N by itself"
End If
End If
End Sub

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Comment out your complete KeyDown event (so you won't lose it in case you
want to go back to it) and then put this demonstration KeyDown event code
in its place...

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If KeyCode = vbKeyN Then
If Shift = 1 Then
MsgBox "You pressed Shift+N"
ElseIf Shift = 2 Then
MsgBox "You pressed Ctrl+N"
ElseIf Shift = 4 Then
MsgBox "You pressed Alt+N"
Else
MsgBox "You pressed just N by itself"
End If
End If
End Sub

Now run the UserForm, place the cursor in the TextBox and press Shift+N,
then press Ctrl+N, then press Alt+N and then just press the N by itself.
Hopefully, the above code will help you to see how to work with this event
(the KeyUp event works the same way).

--
Rick (MVP - Excel)


"Bert" wrote in message
...
Thanks for getting me on the right track. Okay, I want to trap only
Alt-n (or possibly Ctrl-n) at this point, although later I may want to
add other similar combinations. All other keystrokes should be displayed
or triggered as usual (Ctrl-c, for example, should copy selected text).
I'm not sure this is right, but the following subroutine captures the
Alt-n keystrokes; however, I'm not sure how to "release" the non-Alt-n
keystrokes to do what they normally would.
----------------------------------------------
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
Static half1 As Boolean
If half1 Then
' get second half of the key combination.
If KeyCode = 78 Then
Call Placenm ' add name at insertion point
End If
half1 = False
Else
' the next line works as long as the character is a displayable
character.
' do I need to create code to handle each condition/keystroke?
If KeyCode = 18 Then
half1 = True
Else
TextBox1.Text = TextBox1.Text & Chr$(KeyCode)
End If
End If
End Sub
----------------------------------------------
Thanks.
Bert

"Rick Rothstein" wrote in message
...
Use the TextBox's own KeyDown, KeyUp or KeyPress events depending on
what kind of keystroke you want to trap.

--
Rick (MVP - Excel)


"Bert" wrote in message
...
Okay...when I closed the workbook (and Excel) and restarted it, it
worked--both your code and mine. (Actually, I'm using Alt-n - "%n".)
So thanks for sticking with this!
Now I have another problem: When the insertion point is in a textbox
in a Userform, the OnKey method doesn't seem to work. It would appear
that Userforms behave differently. Is this the case? If so, is there
a way to trap specific keystokes in a textbox?
Thanks again.
Bert.

"Gary''s Student" wrote in
message ...
I put the following in Module1:

Sub OffKey()
Application.OnKey "^{+}", "Placenm"
End Sub

Sub Placenm()
MsgBox ("Hello World")
End Sub

I went back to the worksheet and manually ran OffKey. I then touched
CNTRL-SHFT-+ and got the macro to fire.

Try the same on a fresh, new workbook.
--
Gary''s Student - gsnu200827


"Bert" wrote:

Placenm is in the "default" module "Module1".
Bert

"Gary''s Student" wrote in
message
...
Where did you put Placenm?
--
Gary''s Student - gsnu200827


"Bert" wrote:

Thanks; however, as noted, I've tried several different key
combinations--
"%n", "^{+}", and others.
I've tried all control and alt keys in all combinations (with and
without
the shift keys)
It still isn't working.
Any other suggestions?
Bert

"Gary''s Student" wrote
in
message
...
Remember:

1. CNTRL-+ using the numeric keypad will not work
2. to get to the "normal" + key ( the one above the = sign) you
must
touch
CNTRL-SHFT-=

This key combination will drive your macro!
--
Gary''s Student - gsnu2007k


"Bert" wrote:

I'm using Excel 2003 in Vista. I'm using the following code,
but it
doesn't
work.
Application.OnKey "^{+}", "Placenm"
I've placed it in ThisWorkBook in a WorkBook_Open routine.
I've also placed it in a subroutine that gets called
periodically in
the
course of a work session.
I've also tried different key combinations. Nothing seems to
work.
(The
subroutine, "Placenm" is not getting called.)
Any suggestions would be appreciated.
Thanks.
Bert.











  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default OnKey problem

Rick:
Your code works perfectly! You've made it very clear what's doing what.
Thanks again.
Bert

"Rick Rothstein" wrote in message
...
Sorry, I left out the most important statement...

KeyCode = 0

its the one that stops a character from being printed (usually used when
one presses Shift, Ctrl or Alt is pressed in combination with a letter in
order to stop the letter from appearing in the TextBox)...

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If KeyCode = vbKeyN Then
If Shift = 1 Then
MsgBox "You pressed Shift+N"
KeyCode = 0
ElseIf Shift = 2 Then
MsgBox "You pressed Ctrl+N"
KeyCode = 0
ElseIf Shift = 4 Then
MsgBox "You pressed Alt+N"
KeyCode = 0
Else
MsgBox "You pressed just N by itself"
End If
End If
End Sub

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Comment out your complete KeyDown event (so you won't lose it in case you
want to go back to it) and then put this demonstration KeyDown event code
in its place...

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If KeyCode = vbKeyN Then
If Shift = 1 Then
MsgBox "You pressed Shift+N"
ElseIf Shift = 2 Then
MsgBox "You pressed Ctrl+N"
ElseIf Shift = 4 Then
MsgBox "You pressed Alt+N"
Else
MsgBox "You pressed just N by itself"
End If
End If
End Sub

Now run the UserForm, place the cursor in the TextBox and press Shift+N,
then press Ctrl+N, then press Alt+N and then just press the N by itself.
Hopefully, the above code will help you to see how to work with this
event (the KeyUp event works the same way).

--
Rick (MVP - Excel)


"Bert" wrote in message
...
Thanks for getting me on the right track. Okay, I want to trap only
Alt-n (or possibly Ctrl-n) at this point, although later I may want to
add other similar combinations. All other keystrokes should be
displayed or triggered as usual (Ctrl-c, for example, should copy
selected text).
I'm not sure this is right, but the following subroutine captures the
Alt-n keystrokes; however, I'm not sure how to "release" the non-Alt-n
keystrokes to do what they normally would.
----------------------------------------------
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
Static half1 As Boolean
If half1 Then
' get second half of the key combination.
If KeyCode = 78 Then
Call Placenm ' add name at insertion point
End If
half1 = False
Else
' the next line works as long as the character is a displayable
character.
' do I need to create code to handle each condition/keystroke?
If KeyCode = 18 Then
half1 = True
Else
TextBox1.Text = TextBox1.Text & Chr$(KeyCode)
End If
End If
End Sub
----------------------------------------------
Thanks.
Bert

"Rick Rothstein" wrote in message
...
Use the TextBox's own KeyDown, KeyUp or KeyPress events depending on
what kind of keystroke you want to trap.

--
Rick (MVP - Excel)


"Bert" wrote in message
...
Okay...when I closed the workbook (and Excel) and restarted it, it
worked--both your code and mine. (Actually, I'm using Alt-n - "%n".)
So thanks for sticking with this!
Now I have another problem: When the insertion point is in a textbox
in a Userform, the OnKey method doesn't seem to work. It would appear
that Userforms behave differently. Is this the case? If so, is there
a way to trap specific keystokes in a textbox?
Thanks again.
Bert.

"Gary''s Student" wrote in
message ...
I put the following in Module1:

Sub OffKey()
Application.OnKey "^{+}", "Placenm"
End Sub

Sub Placenm()
MsgBox ("Hello World")
End Sub

I went back to the worksheet and manually ran OffKey. I then touched
CNTRL-SHFT-+ and got the macro to fire.

Try the same on a fresh, new workbook.
--
Gary''s Student - gsnu200827


"Bert" wrote:

Placenm is in the "default" module "Module1".
Bert

"Gary''s Student" wrote in
message
...
Where did you put Placenm?
--
Gary''s Student - gsnu200827


"Bert" wrote:

Thanks; however, as noted, I've tried several different key
combinations--
"%n", "^{+}", and others.
I've tried all control and alt keys in all combinations (with and
without
the shift keys)
It still isn't working.
Any other suggestions?
Bert

"Gary''s Student" wrote
in
message
...
Remember:

1. CNTRL-+ using the numeric keypad will not work
2. to get to the "normal" + key ( the one above the = sign) you
must
touch
CNTRL-SHFT-=

This key combination will drive your macro!
--
Gary''s Student - gsnu2007k


"Bert" wrote:

I'm using Excel 2003 in Vista. I'm using the following code,
but it
doesn't
work.
Application.OnKey "^{+}", "Placenm"
I've placed it in ThisWorkBook in a WorkBook_Open routine.
I've also placed it in a subroutine that gets called
periodically in
the
course of a work session.
I've also tried different key combinations. Nothing seems to
work.
(The
subroutine, "Placenm" is not getting called.)
Any suggestions would be appreciated.
Thanks.
Bert.












Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
OnKey Help jutlaux Excel Programming 1 November 16th 06 03:49 PM
OnKey Hernan Excel Programming 2 January 11th 06 04:18 PM
Problem mapping procedure using OnKey Method Adrian[_7_] Excel Programming 1 August 4th 04 12:58 PM
Application.OnKey problem R Avery Excel Programming 0 July 8th 04 06:38 PM
Application.OnKey problem Phillip Reeves[_2_] Excel Programming 1 January 23rd 04 06:46 PM


All times are GMT +1. The time now is 01:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"