0

在 VBA 中有一个文本框并且不希望用户能够在其中输入空格我可以阻止用户通过编程这样做吗?

4

3 回答 3

1
' 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

来自谷歌:D

于 2011-07-17T17:50:58.680 回答
1

处理按键/更改事件,检查“”然后设置为 string.empty。

输入数据后交替使用 string.replace(" ", string.empty)

于 2010-11-03T14:54:46.043 回答
0

也许会帮助你:

您可以在 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

注意:此示例只允许输入数字。您需要根据您的情况对其进行调整。

这是另一个页面几乎相同的例子但英文:LINK

于 2010-11-03T14:55:38.747 回答