none
About Excel vba RRS feed

  • 問題

  •  

    HI

     

      If i want to show which keybroad botton i am pressing on the textbox in Excel's userform, so can i do this by using marco or the other way?

     

    thx for help

    2008年10月16日 上午 08:59

解答

  • Hi Mark,

    I think you would need create a marco so that you can trigger it to detect the key you have pressed on the form or text box. Here it is simple code, feel free to have a try.


    Private Sub Form_KeyPress(KeyAscii As Integer)

     Select Case KeyAscii

     Case Asc("A") To Asc("z")
        MsgBox KeyAscii
     Case Asc("0") To Asc("9")
        MsgBox KeyAscii
     Case vbKeyTab
           MsgBox "TAB"
    case vbKeyEscape
           MsgBox "Escape"
     End Select
    ''In you case you will assign the value into textbox
    End Sub


     I think for "Backspace", "tab" is a bit different. so for Tab or esc you may want to do more SELECT CASE to deal with it E.g. vbKeyTab
    Please read the URL below for more information about the keywords
    http://msdn.microsoft.com/en-us/library/0z084th3(VS.80).aspx

    Hope this can help

    Good luck

    2008年10月20日 上午 08:16

所有回覆

  •  

    1. If the Developer tab is not available, do the following to display it:
      1. Click the Microsoft Office Button , and then click Excel Options.
      2. In the Popular category, under Top options for working with Excel, select the Show Developer tab in the Ribbon check box, and then click OK.

         Note   The Ribbon is a component of the Microsoft Office Fluent user interface.

    2. To set the security level temporarily to enable all macros, do the following:
      1. On the Developer tab, in the Code group, click Macro Security.

      2. Under Macro Settings, click Enable all macros (not recommended, potentially dangerous code can run), and then click OK.

       Note   To help prevent potentially dangerous code from running, we recommend that you return to any of the settings that disable all macros after you finish working with macros.

    3. On the Developer tab, in the Code group, click Macros.
    4. In the Macro name box, click the macro that you want to edit.
    5. Click Edit.
    2008年10月18日 上午 01:47
  • thanks for anrsering frist

     

    but actually i want to know if i already created the textbox1 in userfrom1. So i start the userfrom1, and i press the "Backspace" on the keybroad, so the textbox1 will show "Backspace", or i press "Esc" on the keybroad then  textbox1 will show "Esc"...

    can i do in using by marcos?

     

    2008年10月20日 上午 05:51
  • Hi Mark,

    I think you would need create a marco so that you can trigger it to detect the key you have pressed on the form or text box. Here it is simple code, feel free to have a try.


    Private Sub Form_KeyPress(KeyAscii As Integer)

     Select Case KeyAscii

     Case Asc("A") To Asc("z")
        MsgBox KeyAscii
     Case Asc("0") To Asc("9")
        MsgBox KeyAscii
     Case vbKeyTab
           MsgBox "TAB"
    case vbKeyEscape
           MsgBox "Escape"
     End Select
    ''In you case you will assign the value into textbox
    End Sub


     I think for "Backspace", "tab" is a bit different. so for Tab or esc you may want to do more SELECT CASE to deal with it E.g. vbKeyTab
    Please read the URL below for more information about the keywords
    http://msdn.microsoft.com/en-us/library/0z084th3(VS.80).aspx

    Hope this can help

    Good luck

    2008年10月20日 上午 08:16
  • Thx for the help!

    2008年10月22日 上午 03:23