|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 通用分子式下标()
U = Mid(Application.Caption, 11, 1)
If U = "E" Then
Set QY = Selection
For Each G In QY
G.Select
Set D = Selection
Call LCY(D, K, U)
Next G
ElseIf U = "W" Then
Set D = Selection
Call LCY(D, K, U)
Selection.EndKey Unit:=wdLine
Selection.Font.Subscript = wdToggle
ElseIf U = "P" Then
Set D = ActiveWindow.Selection.ShapeRange.TextFrame.TextRange
Call LCY(D, K, U)
End If
End Sub
Sub LCY(D, K, U)
l = Len(D)
For I = 2 To l
Y = Asc(Mid(D, I - 1, 1))
X = Asc(Mid(D, I, 1))
Q = Y > 64 And Y < 123 Or Y = 41
R = X > 47 And X < 58 And K
If X > 47 And X < 58 And Q Or R Then
If U = " W " Then
D.Characters(I).Font.Subscript = 1
Else
D.Characters(Start:=I, Length:=1).Font.Subscript = 1
End If
K = 1
Else: K = 0
End If
Next I
End Sub
[ 本帖最后由 chuhaiou 于 2010-3-11 11:29 编辑 ] |
|