如何在VBA MS Word 2003文档中将所有提升/降低字符更改为上标/下标字符?
我的非功能性代码:
Public Sub Normalize_Position()
Application.ScreenUpdating = False
Dim uVals() As Variant
Dim Rng As Range
'All these values are font positions
uVals = Array(0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5)
For v = 0 To UBound(uVals)
With Selection
.HomeKey Unit:=wdStory
Set Rng = ActiveDocument.Range
Rng.Collapse Direction:=wdCollapseStart
Rng.Find.ClearFormatting
Rng.Find.Font.position = uVals(v)
Rng.Find.Replacement.ClearFormatting
With Rng.Find
.Text = ""
.Replacement.Text = ""
.Replacement.Font.position = 0
.Replacement.Font.Superscript = 1
.Replacement.Font.Color = wdColorRose
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Rng.Find.Execute Replace:=wdReplaceAll
End With
Next
Application.ScreenUpdating = True
'Free up memory
ActiveDocument.UndoClear
Debug.Print "Normalize font position Finished.!"
End Sub
答案 0 :(得分:0)
Rng.Find.Font.position
字段的类型为long而不是double,因此您不会规范化那些使用小数来提升/降低其位置的字符。
您可以遍历所有字符并检查是否
ActiveDocument.Range.Characters.Item(i).Font.Position > 0
但是,如果您使用大型文档,可能需要很长时间。
如果我找到一个,我会回来找一个解决方案。