How To "Share" Default Behavior With OnKey?

johnywhy

New Member
Joined
Sep 12, 2008
Messages
47
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Platform
  1. Windows
  2. MacOS
Halo

I want to run a macro with OnKey, but then I want the normal key behavior to execute.

Neither of these two approaches work; both produce an endless loop. I'd like a solution which will work with ANY single or combination keystroke.

Sub keyEvent()
Debug.Print "a typed"
With Application
.OnKey "a"
.SendKeys "a"
.OnKey "a", "keyEvent"
End With
End Sub

Public Sub keyEvent()
Debug.Print "a typed"
With Application
.EnableEvents = False
.SendKeys "a"
.EnableEvents = True
End With
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I don't think you can do that with OnKey. Can I ask why - sounds a lot like keylogging to me.
 
Upvote 0
What's keylogging?
The debug.print is just for testing purposes.

I don't want to stop normal key behavior, just add to it.
 
Upvote 0
Keylogging is recording the keystrokes that people make.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top