Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Keyboard input

This is a discussion on Keyboard input within the Excel Questions forums, part of the Question Forums category; Is there a way, using a macro, to determine what a keyboard character is? Something like: If Keyboard input = ...

  1. #1
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869

    Default Keyboard input

    Is there a way, using a macro, to determine what a keyboard character is? Something like:

    If Keyboard input = Char(13) Then
    Do something
    End If

  2. #2
    MrExcel MVP Zack Barresse's Avatar
    Join Date
    Dec 2003
    Location
    Oregon, USA
    Posts
    10,470

    Default

    you can assign macros to shortcuts from the keyboard, if that is what you mean.
    Regards,
    Zack Barresse
    My book on Excel Tables
    ExcelTables.com
    All Excel Functions
    (If you would like comments in any code, please say so.)

  3. #3
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869

    Default

    No, that is not what I mean. I want to monitor keyboard inputs while entering into a text box and when the Enter key is found to have been depressed, do some things.

  4. #4
    MrExcel MVP
    Int'l Moderator
    Greg Truby's Avatar
    Join Date
    Jun 2002
    Location
    39 17' 15" N, -94 40' 26" W
    Posts
    9,770

    Default Re: Keyboard input

    If you mean, can you run a macro after you've started to enter something into a cell, but before you hit the [Enter] key, then no. While in Edit mode you cannot execute a macro.

    If you mean, can you trap for certain values having been entered into a cell after you hit the [Enter] key and you back out of Edit mode then yes, you can use the _Change() event handlers to take some action based on what was entered into a cell.
    Greg

    Work: XL 2003, 2007 and 2010 on Windows 7
    Please use CODE tags - especially for longer excerpts of code.

  5. #5
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869

    Default

    What I am trying to do is enter things into a TEXTBOX, not a cell. each keystroke will give a Change event. I want to look at each keyboard entry at that change event to determine if it was the enter key that was depressed. is this possible?

  6. #6
    MrExcel MVP Tom Urtis's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, California USA
    Posts
    11,008

    Default Re: Keyboard input

    Maybe yes, maybe no; you need to clarify 2 points first:

    (1)
    What kind of TextBox are you talking about? AutoShape? Forms on sheet? ActiveX on sheet? Userform? What?

    (2)
    Why are you interested in the Enter key? Because it's the Enter key? Or because you want to monitor when the TextBox is exited? If so, what about the Tab key, which will also allow for TextBox exit? You might need an Exit event instead.

    So you see, a little more info from you would go a long way to getting an answer.

  7. #7
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869

    Default

    thanks Tom, this is an active X, created from the Control ToolBox. It is not on a user form. I want to use the Enter key, because the standard for a completed entry is the enter key.

  8. #8
    MrExcel MVP Tom Urtis's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, California USA
    Posts
    11,008

    Default Re: Keyboard input

    What do you mean by "the standard"? If they type in some gobbledy-gook and click some cell, that de facto enters the gobbledy-gook. Will that be OK for you, and you won't want to protect against that?

  9. #9
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869

    Default

    Look, I am trying to use a control box created text box to enter some data. I dont want to use it on a user form. I would like the user to be able to enter whatever they want, then press the enter key and have a macro then shift the focus of that control box created text box onto another one. All I am trying to find out is if this is possible and if so, how to do it. The change event for the text box detects any keystroke. At each change event, I would like to look at what that change was and then initiate code.

  10. #10
    MrExcel MVP Tom Urtis's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, California USA
    Posts
    11,008

    Default Re: Keyboard input

    Here's the code for hitting Enter in a an ActiveX TextBox. The code goes in the worksheet module upon which the TextBox resides. Modify for name of TextBox.


    Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = vbKeyReturn Then
    MsgBox "It's your thang..." & vbCrLf & "Do whatcha wanna do...", 64, "Enter was clicked."
    KeyCode = 0
    End If
    End Sub

Page 1 of 2 12 LastLast

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com