[算表] excel, vba, userform, textbox

看板Office作者 (火靈)時間16年前 (2010/02/06 11:15), 編輯推噓2(203)
留言5則, 3人參與, 最新討論串1/2 (看更多)
軟體: Excel 版本: 2003 Userform1 OptionButton1 Optionbutton2 ████████████████ 如圖... 當我在下面的TextBox1中輸入資訊 最後鍵下 Enter後 達成我要的目標 但是附帶一個我不要的效果想要取消.... 當我鍵下 Enter 後 它會自動轉移到 OptionButton1 導致我沒辦法直接重新輸入資訊 我的希望是 我只要一直重複 資訊-> Enter 資訊-> Enter .... 不需要 Enter 後重新點選 textbox1 或者按兩下 Tab 請問該怎樣設定選項?? 或者該怎樣寫?? 新手摸黑亂試... 請各位先進幫幫忙 3Q 另外 謝謝之前 lantolerance 以及 Steven0422 兩位先進幫忙解惑 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.70.46.61

02/06 17:05, , 1F
控制項的SetFocus方法
02/06 17:05, 1F

02/06 18:35, , 2F
恩 try不出要的結果 Orz
02/06 18:35, 2F

02/06 18:47, , 3F
TextBox輸入完資料按Enter? 不太懂這段??
02/06 18:47, 3F
Userform1 Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = vbKeyReturn Then If TextBox1.Value <> "" Then If UserForm1.OptionButton1.Value = True Then ActiveCell.Value = "type1" Module1.type1 ElseIf UserForm1.OptionButton2.Value = True Then ActiveCell.Value = "type2" Module1.type2 Else MsgBox "請選擇類別~" End If TextBox1.Value = "" Else MsgBox "請輸入內容" End If End If End Sub Module1 Sub type1() ActiveCell.Offset(0, 1).Value = UserForm1.TextBox1.Value ActiveCell.Offset(1, 0).Select End Sub --------------------------------------------------------- Sub type2() ActiveCell.Offset(0, 2).Value = UserForm1.TextBox1.Value ActiveCell.Offset(1, 0).Select End Sub 我剛剛在想 textbox1.setfocus 的動作 似乎是在整個 Sub TextBox1_KeyDown~End sub之中 但是選擇位置的自動轉移 好像是在 Sub TextBox1_KeyDown~End sub之後?? ※ 編輯: firelf 來自: 219.70.46.99 (02/06 19:37) ※ 編輯: firelf 來自: 219.70.46.99 (02/06 19:47) ※ 編輯: firelf 來自: 219.70.46.99 (02/06 19:50)

02/08 16:09, , 4F
應可將textbox1.setfocus 加在綠色IF結束後與
02/08 16:09, 4F

02/08 16:10, , 5F
藍色IF結束前 之間 (這樣描述好像不太清楚…^^a)
02/08 16:10, 5F
文章代碼(AID): #1BRDx3VO (Office)
討論串 (同標題文章)
文章代碼(AID): #1BRDx3VO (Office)