Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyReturn Then
If TextBox1.Value < 1 Or TextBox1.Value > 100 Then
MsgBox "你输入的数据有误,只能输入1-100之间的数据"
TextBox1.Text = ""
Else
MsgBox TextBox1.Value
TextBox1.Text = ""
End If
End If
End Sub
试看看