Powerpoint VBA 上标数字

Powerpoint VBA Superscript Numbers

我一直在尝试创建一个宏,将幻灯片上文本框中的所有 数字 转换为上标,但我发现 Powerpoint VBA 很奇怪。

我已经尝试将这一行简短的代码作为入门,但这似乎 select 不正确。

ActivePresentation.Slides(1).Select.Font.superscript = True

如有任何帮助,我们将不胜感激。

谢谢!

首先,永远不要 select 任何东西,除非你绝对必须(很少,非常罕见)。 接下来,您 select 编辑了一个幻灯片对象。幻灯片没有任何字体属性,因此您无法设置它们。

这是一个将当前 selected 形状中的所有字符设置为上标的示例。您可能希望对其进行优化以遍历幻灯片中的所有形状,并跳过所有非数字字符。 [编辑为超级而不是下标字符和仅数字字符]

Sub SuperscriptMe()

Dim oSh As Shape
Dim x As Long

Set oSh = ActiveWindow.Selection.ShapeRange(1)

With oSh.TextFrame.TextRange
    For x = 1 To .Characters.Count
        ' verify that the character is a number
        If IsNumeric(.Characters(x)) then
           .Characters(x).Font.Superscript = True
        End If
    Next
End With

End Sub