vba 防止在文本框中输入空格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4088220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Prevent spaces in textbox being enterd
提问by John mc Niel
Got a textbox in VBA and dont want the usser to be able to type spaces in it can i prevent the usser from doing this with programing?
在 VBA 中有一个文本框,并且不希望用户能够在其中键入空格,我可以防止用户通过编程来执行此操作吗?
回答by Mr Shoubs
回答by Viper
Maybe thiswill help you:
也许这会帮助你:
You can allow/disallow specific buttons in the KeyPress-Event
您可以允许/禁止 KeyPress-Event 中的特定按钮
Private Sub TextBox1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case asc("0") To asc("9"), 8, 32, asc(",")
'allow signs
Case Else
KeyAscii = 0 'forbid everything else
End Select
End Sub
NOTE: This example allows only numbers to be entered. You need to adapt it for your case.
注意:此示例只允许输入数字。你需要根据你的情况调整它。
Here is another page with nearly the same example but in english: LINK
这是另一个具有几乎相同示例但英文的页面:LINK
回答by Daniel G. Wilson
' Disable Space in TextBox
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 32 Then
KeyAscii = 0
End If
End Sub
http://www.vbforums.com/showthread.php?t=447978
http://www.vbforums.com/showthread.php?t=447978
From google :D
来自谷歌:D