|
VBA万岁 发表于 2014-5-2 15:42 
附件如下:
类:- Public WithEvents Txtbox As MSForms.TextBox
- Private Sub Txtbox_Change()
- Dim s As String, t As String, a, i As Integer
- s = Txtbox.Text
- If InStr(s, ".") Then
- If Left(s, 1) = "." Then
- Txtbox.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
- Txtbox.Text = t
- End If
- End If
- End If
- With CreateObject("vbscript.regexp")
- .Global = True
- .Pattern = "[^0-9.]+"
- If .test(s) Then
- Txtbox.Text = .Replace(s, "")
- End If
- End With
- Txtbox.SelStart = Len(s)
- End Sub
复制代码 |
|