Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to intercept each pressed key

In real VB I can intercept each pressed key with the following code
before e.g. the character of the pressed key is added to a TextBox:

Private Sub Form_Load()
Me.KeyPreview = True
...
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
MsgBox ("The key " & KeyCode & " has been pressed.")
End Sub

Is there a way to do something similar in VBA (e.g. Excel)?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default How to intercept each pressed key

Are you wanting to intercept key strokes within a cell? If so then the answer
is no as no events fire while a cell is in edit mode.
--
HTH...

Jim Thomlinson


"Stefan Mueller" wrote:

In real VB I can intercept each pressed key with the following code
before e.g. the character of the pressed key is added to a TextBox:

Private Sub Form_Load()
Me.KeyPreview = True
...
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
MsgBox ("The key " & KeyCode & " has been pressed.")
End Sub

Is there a way to do something similar in VBA (e.g. Excel)?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to intercept each pressed key

No, I'd like to intercept key strokes within a UserForm.
E.g. if you press F5 I'd like to do a refresh of a ListBox.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default How to intercept each pressed key

I concur with Jim. Further to his response, the only way to do this is to run
a loop and monitor keystrokes using API code. I think PeekMessage and
DispatchMessage. If the need is only temporary and it's particularaly
important, then it may be worth it. But I doubt it.

Say, you click a button and it goes into this loop where it monitors each
keystroke and acts as if Excel is in edit mode but isn't actually. You are
intercepting the keystrokes and concatenating to the active cell and also
doing whatever with each keystroke. I don't think you would want to invoke
the loop by double clicking the same way you would go into Excel's edit mode.

Regards,
Greg

"Stefan Mueller" wrote:

In real VB I can intercept each pressed key with the following code
before e.g. the character of the pressed key is added to a TextBox:

Private Sub Form_Load()
Me.KeyPreview = True
...
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
MsgBox ("The key " & KeyCode & " has been pressed.")
End Sub

Is there a way to do something similar in VBA (e.g. Excel)?


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
Regression with zero intercept TheMoth Excel Worksheet Functions 2 January 19th 08 10:14 PM
regression using set intercept Canary Pete Excel Discussion (Misc queries) 4 November 18th 06 02:37 PM
Regression intercept to 0 squalidae Excel Worksheet Functions 2 February 22nd 06 05:56 AM
Intercept and Indirect Graham Haughs Excel Worksheet Functions 2 February 19th 06 06:51 AM
B = Y Intercept Alex A Excel Programming 1 January 24th 04 01:48 AM


All times are GMT +1. The time now is 02:20 AM.

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

About Us

"It's about Microsoft Excel"