[問題] vba表單 Keydown 遇到SetFocus

作者: waiter337 (給開司一罐蘇格登)   2016-12-09 01:57:50
目前有個疑問
假設有兩個控件
textbox1

CommandButton1
當我用
Private Sub TextBox1_Keydown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode.Value = 13 And TextBox1.Text <> "" Then
textbox1.Setfocus
這種方式在textbox1上面輸入數字後 按下enter
光標卻一直跳去CommandButton1
懷疑是
1.按下enter 程式確實執行完成,光標跳至textbox1
2.當我放開enter ,結果照著excel預設值,就又跳去CommandButton1
我想要一直在textbox1 一直連續輸入
譬如 textbox1
a > enter > b > enter ........
都不會跳開textbox1
請問
除了關掉預設之外,
這個程式的邏輯該如何下
作者: soyoso (我是耀宗)   2016-12-09 08:00:00
判斷內加上keycode=0
作者: waiter337 (給開司一罐蘇格登)   2016-12-09 19:13:00
搞定 感謝!

Links booklink

Contact Us: admin [ a t ] ucptt.com