Const xStr As String = "0123456789" '先聲明一個常量,並把你想禁用或允許輸入的內容賦值給它 Private Sub Text1_KeyPress(KeyAscii As Integer) '只能輸入數字 KeyAscii = IIf(InStr(xStr & Chr(8), Chr(KeyAscii)), KeyAscii, 0) End Sub Private Sub Text2_KeyPress(KeyAscii As Integer) '只能輸入數字以外的字符 KeyAscii = IIf(InStr(xStr, Chr(KeyAscii)), 0, KeyAscii) End Sub