|
这段代码可以用提速吗?详见附件,目的是把“.0123456789()+-*/^%”之外及“[]”和“{}”的字符分开上色。
Public sSize As Byte, zSize As Byte
Public Sub BZ1(Rng As Range)
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
If sSize = 0 Then sSize = 10
If zSize = 0 Then zSize = 7
Dim XX1(100), XX2(100), XX3(100), XX4(100)
With Rng.Font
.Size = sSize
.ColorIndex = 1
End With
For Each S In Rng
ii = 0
For i = 1 To Len(S)
Select Case Mid(S, i, 1)
Case "{"
ii = ii + 1: i0 = i: XX1(ii) = i
Do Until Mid(S, i, 1) = "}"
i = i + 1: If i > Len(S) Then Exit Do
Loop
XX2(ii) = i - i0 + 1: XX3(ii) = 3: XX4(ii) = sSize
Case "0" To "9", "+", "-", "*", "/", "(", ")", "^", ".", "(", ")"
Case "["
ii = ii + 1: i0 = i: XX1(ii) = i
Do Until Mid(S, i, 1) = "]"
i = i + 1: If i > Len(S) Then Exit Do
Loop
XX2(ii) = i - i0 + 1: XX3(ii) = 32: XX4(ii) = zSize
Case Else
ii = ii + 1: i0 = i: XX1(ii) = i
Do While InStr(".0123456789+-*/%^()()", Mid(S, i, 1))
i = i + 1: XX1(ii) = i
Loop
XX2(ii) = i - i0 + 1: XX3(ii) = 32: XX4(ii) = zSize
End Select
Next i
For k = 1 To ii
With Cells(S.Row, S.Column).Characters(Start:=XX1(k), Length:=XX2(k)).Font
.ColorIndex = XX3(k)
.Size = XX4(k)
End With
Next k
Next S
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
[ 本帖最后由 Zamyi 于 2009-6-26 22:07 编辑 ] |
|