2014-02-28 69 views
0

我想讓這個文本框:如果我輸入「clean」並按回車,我希望它採取下面的操作。有什麼辦法可以實現它嗎?這是我的嘗試。VBA - 按回車繼續命令

Private Sub TextBox1_Change() 

If TextBox1.Text = "clean" + KeyCode(13) Then 
Shell "cmd /c cleanmgr.exe", vbHide 
End If 
End Sub 

謝謝。

回答

2

這可能是你在找什麼:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) 

    If KeyCode = 13 Then 
     If TextBox1.Text = "clean" Then 

      MsgBox "ok" 'for test 
      'do your stuff here!! 

     End If 
    End If 

End Sub 
+0

謝謝!有效! – user3273965