▽1
●
うぃんど ベストアンサー |
どのタイミングで何をやりたいのかがわからなかったのでスルーしてたのですが、
キャンセルして質問文作り直しされたので、パズルがてらやってみました
Private Sub CheckBox1_Click() With TextBox1 If CheckBox1 = True Then .Enabled = True: 'テキストボックスを有効化 .Value = "": 'テキストボックスを空っぽに .BackColor = &HC0FFC0: '背景色を元の色に .Activate Else .Enabled = False: 'テキストボックスを無効化 .BackColor = &HC0C0C0: '判りやすいように背景をグレーに End If End With End Sub Private Sub TextBox1_KeyPress(ByVal KeyCode As MSForms.ReturnInteger) ' 数値と小数点以外の文字は無効化するための処理 If KeyCode >= 48 And KeyCode <= 57 Then ' 0-9 ElseIf KeyCode = 46 And InStr(TextBox1.Value, ".") = 0 Then ' 小数点 Else ' その他のキー KeyCode = 0 End If End Sub Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) ' Enterキーの判定はこちらで行う If KeyCode = 13 Then CommandButton1.Activate End If End Sub Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) MsgBox "CommandButton1が押されたよ" & vbCrLf & "値は[" & TextBox1.Value & "]だね" End Sub