|
sspgyi 发表于 2014-5-2 19:02 
你好!如果变成两个文本框,一个文本框只能输入数字,另一个只能输入字母,如何解决呢?请帮忙,谢谢!
增加一个类模块(clsTxt2):
Public WithEvents Txtbox2 As MSForms.TextBox
Private Sub Txtbox2_Change()
Dim s As String, t As String, a, i As Integer
s = Txtbox2.Text
If InStr(s, ".") Then
If Left(s, 1) = "." Then
Txtbox2.Text = Mid(s, 2)
Else
a = Split(s, ".")
If UBound(a) > 1 Then
t = a(0) & "."
For i = 1 To UBound(a)
t = t & a(i)
Next
Txtbox2.Text = t
End If
End If
End If
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = "[^A-z.]+"
If .test(s) Then
Txtbox2.Text = .Replace(s, "")
End If
End With
Txtbox2.SelStart = Len(s)
End Sub
|
|