1

如何在 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
4

1 回答 1

0

Rng.Find.Font.position字段的类型为 long not double,因此您不会规范化那些使用小数来提高/降低其位置的字符。

您可以遍历所有字符并检查是否

ActiveDocument.Range.Characters.Item(i).Font.Position > 0

但这可能需要很长时间,尤其是在处理大型文档时。

如果我能找到一个解决方案,我会回来的。

于 2014-08-14T14:27:03.013 回答