在PowerPoint中查找并替换上标
是否有一种方法可以自定义下面的代码(用于更大的下标和上标)来搜索SuperScript A,B,C…。并用数字1、2、3…在PowerPoint中代替它们。
任何帮助都将不胜感激。
代码的源。
Sub BumpTheSubsAndSupers()
Dim oSl As Slide
Dim oSh As Shape
Dim x As Long
Dim dBumpBy As Double
dBumpBy = 4 ' number of points to bump sub/superscript by
' Check each slide
For Each oSl In ActivePresentation.Slides
' Check each shape on the slide
For Each oSh In oSl.Shapes
' Make sure it's got text
If oSh.HasTextFrame Then
If oSh.TextFrame.HasText Then
With oSh.TextFrame.TextRange
For x = 1 To .Runs.Count
If .Runs(x).Characters.Font.BaselineOffset <> 0 Then
' it's a sub/super; make it four points
' bigger than the text immediately prior:
.Runs(x).Characters.Font.Size = _
.Runs(x - 1).Characters.Font.Size + dBumpBy
End If ' it's a sub/superscript
Next x
End With ' textframe.textrange
End If ' .HasText
End If ' .HasTextFrame
Next oSh '
Next oSl
End Sub
Is there a way to customize the code below (for making subscripts and superscripts larger) to search for superscript a , b, c …. and replace them with numbers 1, 2, 3 …in PowerPoint.
Any help would be much appreciated.
Sub BumpTheSubsAndSupers()
Dim oSl As Slide
Dim oSh As Shape
Dim x As Long
Dim dBumpBy As Double
dBumpBy = 4 ' number of points to bump sub/superscript by
' Check each slide
For Each oSl In ActivePresentation.Slides
' Check each shape on the slide
For Each oSh In oSl.Shapes
' Make sure it's got text
If oSh.HasTextFrame Then
If oSh.TextFrame.HasText Then
With oSh.TextFrame.TextRange
For x = 1 To .Runs.Count
If .Runs(x).Characters.Font.BaselineOffset <> 0 Then
' it's a sub/super; make it four points
' bigger than the text immediately prior:
.Runs(x).Characters.Font.Size = _
.Runs(x - 1).Characters.Font.Size + dBumpBy
End If ' it's a sub/superscript
Next x
End With ' textframe.textrange
End If ' .HasText
End If ' .HasTextFrame
Next oSh '
Next oSl
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很棒的问题!
我已经修改了要执行的代码(将大小和切换字母更改为数字)。
如果您愿意,您都可以发表评论的任何部分。毫无疑问,这样做的方法更有效(例如,将一系列的字母数量而不是一次分配给每个下标),但这几乎是在适度尺寸的文件上即可。优化它所需的时间可能会超过其保存的时间。
如果您将其他字母的字母用作子/超级订阅,则需要将它们添加到OrdinalFromletter函数中。
Great question!
I've modified the code to do both (change the size and switch letters to numbers).
You can comment out whichever part you don't want if you like. There are doubtless more efficient ways of doing this (like splitting the array of letters once rather than once for each subscript) but it's all but instant on moderately sized files; the time it'd take to optimize it would probably exceed the time it'd save in use.
If you use letters from other alphabets as sub/superscripts, you'll want to add them to the OrdinalFromLetter function.