语境
我有主幻灯片和 60 张布局幻灯片。不要问为什么,但我想在主幻灯片及其 60 张布局幻灯片中的虚拟文本、标题中查找和替换文本。
我已尝试过...
...是切换到幻灯片母版,然后按 ctrl+F 使用“查找”对话框。但是,当我按按钮 [查找下一个] 启动“查找”时,PowerPoint 立即切换回普通视图并在实际演示文稿内容中搜索。
问题
有没有办法在主幻灯片及其布局幻灯片中的虚拟占位符文本中查找和替换?
答案1
事实证明你可以用一点 VBA 来进行搜索/替换:
' Use this to test the replacement
' Usage: Call ReplaceTextInLayouts (text to replace, text to replace it with)
Sub TestReplace()
Call ReplaceTextInLayouts("BETTER", "WORSE")
End Sub
Sub ReplaceTextInLayouts(sSearchFor As String, sReplaceWith As String)
Dim oSh As Shape
Dim oLay As CustomLayout
With ActivePresentation
For Each oLay In .SlideMaster.CustomLayouts
For Each oSh In oLay.Shapes
If oSh.HasTextFrame Then
With oSh.TextFrame.TextRange
If InStr(.Text, sSearchFor) > 0 Then
Call .Replace(sSearchFor, sReplaceWith)
End If
End With
End If
Next
Next
End With
End Sub