如何使用VBA在powerpoint中查找和替换字符串

Rah*_*gli -2 powerpoint vba powerpoint-vba

我想在ppt的幻灯片1中将"hello"替换为"world".如何使用VBA脚本执行此操作.

Rah*_*gli 7

Sub findAndReplaceText()
Dim sld As Slide
Set sld = ActivePresentation.Slides(1)
Dim shp As Shape
For Each shp In sld.Shapes
If shp.HasTextFrame Then
    If shp.TextFrame.HasText Then
        shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "hello", "world")
    End If
End If
Next shp
End Sub
Run Code Online (Sandbox Code Playgroud)

参考:https://www.youtube.com/watch?v = BYKKVmtAGE

  • 请注意,这不会保留任何特定于行或部分的格式,因为它会替换形状中的所有文本 (2认同)