参考网上例子,在PPT中批量设置m3的3为上标的VBA

发布时间 2023-08-16 10:06:30作者: 而且
 1 Sub Replace_m3_to_supscript()
 2     Dim sld As Slide
 3     Dim shp As Shape
 4     Dim txtRng As TextRange
 5     Dim i As Long
 6     For Each sld In ActivePresentation.Slides
 7         For Each shp In sld.Shapes
 8             If shp.HasTextFrame And shp.TextFrame.HasText Then
 9                 Set txtRng = shp.TextFrame.TextRange
10                 For i = 1 To Len(txtRng)
11                     If Mid(txtRng, i, 1) = "m" Then
12                         If Mid(txtRng, i + 1, 1) = "3" Then
13                             txtRng.Characters(i + 1, 1).Font.Superscript = msoTrue
14                         End If
15                     End If
16                 Next i
17             End If
18         Next shp
19     Next sld
20 End Sub

如要设置下标,则改txtRng.Characters(i + 1, 1).Font.Subscript = msoTrue