[問題] vba表單 Keydown 遇到SetFocus

看板Office作者 (給開司一罐蘇格登)時間9年前 (2016/12/09 01:57), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/1
目前有個疑問 假設有兩個控件 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 請問 除了關掉預設之外, 這個程式的邏輯該如何下 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.35.158.244 ※ 文章網址: https://www.ptt.cc/bbs/Office/M.1481219872.A.25B.html

12/09 08:00, , 1F
判斷內加上keycode=0
12/09 08:00, 1F

12/09 19:13, , 2F
搞定 感謝!
12/09 19:13, 2F
文章代碼(AID): #1OIPyW9R (Office)
文章代碼(AID): #1OIPyW9R (Office)