|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
回复 1楼 水星钓鱼 的帖子
Sub 智能上下标()
Dim x, Y, j, k As Integer
Dim m, n As Long
Dim char As String
x = Selection.Start
Y = Selection.End
For j = x To Y Step 1
Selection.Start = j - 1
Selection.End = j
char = Selection.Text
n = InStr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ))]", char)
If n <> 0 Then
Selection.Start = j
Selection.End = j + 1
char = Selection.Text
m = InStr("0123456789", char)
If m <> 0 Then
k = 2
Selection.Font.subScript = wdToggle
Selection.Start = j
Selection.End = j + k
char = Selection.Characters(k).Text
m = InStr("0123456789-+", char)
Do While m <> 0
If char = "+" Or char = "-" Then
Selection.Start = j + k
Selection.End = j + k + 1
char = Selection.Text
m = InStr("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ(([", char)
If m <> 0 Then
GoTo LINE1
Else
Selection.Start = j - 1
Selection.End = j + k
char = Selection.Characters(1).Text
End If
If char = "O" Or char = "H" Then '与line1共同作用以防止将NH4+、AlO2-
Selection.Start = j
Selection.End = j + 1
Selection.Font.subScript = wdToggle
Selection.Font.subScript = wdToggle
Selection.Start = j + 1
Selection.End = j + k
Selection.Font.Superscript = wdToggle
GoTo LINE1
End If
Selection.Start = j
Selection.End = j + k
Selection.Font.Superscript = wdToggle
Selection.Font.Superscript = wdToggle
GoTo LINE1
End If
k = k + 1
Selection.Start = j
Selection.End = j + k
char = Selection.Characters(k).Text
If char = "-" Or char = "+" Then
Selection.Start = j
Selection.End = j + k - 2
Selection.Font.subScript = wdToggle
Selection.Font.subScript = wdToggle
Selection.Start = j + k - 2
Selection.End = j + k
Selection.Font.Superscript = wdToggle
GoTo LINE1
Else
m = InStr("0123456789", char)
End If
Loop
Selection.Start = j
Selection.End = j + k - 1
Selection.Font.subScript = wdToggle
Selection.Font.subScript = wdToggle
End If
LINE1:
Selection.Start = j
Selection.End = j + 1
char = Selection.Text
m = InStr("-", char)
If m <> 0 Then
Selection.Start = j + 1
Selection.End = j + 2
char = Selection.Text
m = InStr("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ(([", char)
If m = 0 Then
Selection.Start = j
Selection.End = j + 1
Selection.Font.Superscript = wdToggle
End If
End If
m = InStr("+", char)
If m <> 0 Then
Selection.Start = j + 1
Selection.End = j + 2
char = Selection.Text
m = InStr("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ(([+", char)
If m = 0 Then
Selection.Start = j
Selection.End = j + 1
Selection.Font.Superscript = wdToggle
End If
End If
End If
Next j
Selection.Start = Y
Selection.End = Y
End Sub |
|