erqie

学无止境,唯缺光阴;理虽无难,贵在有恒。

导航

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

Posted on 2023-08-16 10:03  而且  阅读(79)  评论(0编辑  收藏  举报
 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