返回列表 上一主題 發帖

如何使用多個KeyCode~TextBox1.Activate能使用迴圈撰寫嗎?(已解決,感謝O大)

如何使用多個KeyCode~TextBox1.Activate能使用迴圈撰寫嗎?(已解決,感謝O大)

本帖最後由 av8d 於 2011-9-12 11:32 編輯

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    i = 49
    For j = 8 To 13
    If KeyCode = i Then
    工作表1.OLEObjects("TextBox" & j).Activate
    i = i + 1
    Next
    End If
End Sub


以上該如何撰寫才能寫出迴圈?(如下)
    If KeyCode = 49 Then
    TextBox8.Activate
    End If

    If KeyCode = 50 Then
    TextBox9.Activate
    End If

    If KeyCode = 51 Then
    TextBox10.Activate
    End If

以此類推~

  1. Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  2.   i = KeyCode
  3.   If i < 49 Or i > 57 Then Exit Sub
  4.   Me.OLEObjects("TextBox" & i - 41).Activate
  5. End Sub
複製代碼

TOP

        靜思自在 : 慈悲沒有敵人,智慧不起煩惱。
返回列表 上一主題