Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7707987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:29:45+00:00 2026-06-01T00:29:45+00:00

Using Application.OnKey <key>, <procedure> , I can cause Excel to run <procedure> whenever <key>

  • 0

Using Application.OnKey <key>, <procedure>, I can cause Excel to run <procedure> whenever <key> is pressed.

What I’d like is for it to do whatever pressing <key> would have done by default, and then run <procedure>. In other words, I don’t want to use OnKey to override what a key does, I want to use it to add to what a key does.

Background Info:

I’m using a barcode scanner that acts just like a keyboard when it scans something, typing in the characters of the barcode, followed by a carriage return (char 13). This carriage return does trigger Excel’s OnKey "~" event.

Right now, I can scan a barcode, and it puts the barcode’s value in the cell, then moves down to the next cell. This is a good start. What I want to do is have Excel run some code along with this, so that it puts the value in the cell, moves down a cell, then runs a procedure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:29:47+00:00Added an answer on June 1, 2026 at 12:29 am

    Why not just “rethrow” the carriage return using SendKeys, and let Excel deal with it as it sees fit? Admittedly, this is a kludge, but perhaps no more so than the rest of your code as you describe it! It would be the simplest and most readable solution — if it works.

    Sub PlainOldCarriageReturn()
    
        Application.EnableEvents = False ' So it won't trigger OnKey.
        Application.SendKeys "~", True ' Send a carriage return.
        DoEvents ' Process the carriage return.
        Application.EnableEvents = True ' Back to normal
    
    End Sub
    

    Just put PlainOldCarriageReturn at the beginning of the procedure called by OnKey.

    My cursory testing indicates that this does works, but you’ll want to test it yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Application run to call several macros in order like this. Sub Run_All_Macros()
Using Application.Quit in Excel VBA is supposed to initiate the default quit procedure, which
I'm getting in trouble. I'm trying to emulate the call Application.Run using Application.DoEvents... this
Can we execute a batch file (*.bat) using Application Domain?
In WinForms you can get a list of all open windows using Application.OpenForms? Is
How can I send notification using application on Facebook? As I know this function
Greetings, I am trying to run an SQL Script uploaded using Application Express (APEX),
I've registered a message filter using Application.AddMessageFilter(m_messageFilter); using this I can log all of
I am using application builder and setting up select boxes to populate a query
What is the necessity of using Application.DoEvents and when we should use it?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.