Find & replace text on a single or selected slides.
#Include <PowerPoint.au3>
_PPT_TextFindReplace($oPresentation, $sFindText, $sReplaceText[, $vSlides = 0[, $vShapes = 0[, $iOccurrence = 0[, $bMatchCase = False[, $bWholeWords = False]]]]])
Parameters
$oPresentation | Object of the presentation to process. |
$sFindText | The text to be searched for. |
$sReplaceText | The replacement text. To delete found text use an empty string (""). |
$vSlides | [optional] Slides to process. See Remarks (default = 0 = all Slides). |
$vShapes | [optional] Shapes to process on each selected Slide. See Remarks (default = 0 = all Shapes). |
$iOccurrence | [optional] Number of times to replace $sFindText in a TextFrame (default = 0 = all occurrences). |
$bMatchCase | [optional] Determines whether a distinction is made on the basis of case (default = False). |
$bWholeWords | [optional] Determines whether only whole words are found (default = False). |
Return Value
Success: 1, @extended holds the number of successfully performed replacements.
Remarks
With this function you can delete a single Shape from multiple Slides or multiple Shapes from a single Slide.
Related
See Also
https://www.thespreadsheetguru.com/the-code-vault/find-and-replace-all-powerpoint-vba-macro
Example
#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=N
#include <PowerPoint.au3>
#include <MsgBoxConstants.au3>
; *************************************************
; Create application object and open a presentation
; *************************************************
Global $oPPT = _PPT_Open()
If @error Then Exit MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_TextFindReplace Example", "Error creating the PowerPoint application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open presentation
Global $sPresentation = @ScriptDir & "\Presentation1.pptx"
Global $oPresentation = _PPT_PresentationOpen($oPPT, $sPresentation)
If @error Then
MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_TextFindReplace Example", "Error opening presentation '" & $sPresentation & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_PPT_Close($oPPT)
Exit
EndIf
; ***********************************************************************************************
; Replace Text ...
; ***********************************************************************************************
MsgBox($MB_ICONINFORMATION, "PowerPoint UDF: _PPT_TextFindReplace Example 1", "Presentation before Replace!", 5)
Global $sFindText = "Test", $sReplaceText = "xyz"
_PPT_TextFindReplace($oPresentation, $sFindText, $sReplaceText, "1-2", 0, 1)
If @error Then Exit MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_TextFindReplace Example 1", "Error replacing text." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_ICONINFORMATION, "PowerPoint UDF: _PPT_TextFindReplace Example 1", "Text replaced " & @extended & " times in the specified range!")